Java Code Examples for javax.swing.JComponent#repaint()

The following examples show how to use javax.swing.JComponent#repaint() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Rails   File: GridPanel.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * highlights given component by altering its border's attributes
 */
protected void setHighlight(JComponent comp,boolean isToBeHighlighted) {
    //quit if nothing is to be done
    if (isToBeHighlighted && highlightedComps.contains(comp)) return;
    if (!isToBeHighlighted && !highlightedComps.contains(comp)) return;

    if (comp.getBorder() instanceof FieldBorder) {
        FieldBorder fb = (FieldBorder)comp.getBorder();
        fb.setHighlight(isToBeHighlighted);
        comp.repaint();
        if (isToBeHighlighted) {
            highlightedComps.add(comp);
        } else {
            highlightedComps.remove(comp);
        }
    }
}
 
Example 2
private static void checkVisibility(JComponent comp) {
    if (comp == null) return;

    comp.invalidate();
    comp.revalidate();
    comp.doLayout();
    comp.repaint();

    for (Component c : comp.getComponents())
        if (c.isVisible()) {
            comp.setVisible(true);

            return;
        }

    comp.setVisible(false);
}
 
Example 3
void repaintComponents()
{
  synchronized (components) {
    for (final JComponent comp : components) {
      comp.invalidate();
      comp.repaint();
    }
  }
}
 
Example 4
Source Project: Rails   File: GridPanel.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void removeAllHighlights() {
    for (JComponent c : highlightedComps) {
        if (c.getBorder() instanceof FieldBorder) {
            FieldBorder fb = (FieldBorder)c.getBorder();
            fb.setHighlight(false);
            c.repaint();
        }
    }
    highlightedComps.clear();
}
 
Example 5
void repaintComponents()
{
  synchronized (components) {
    for (final JComponent comp : components) {
      comp.invalidate();
      comp.repaint();
    }
  }
}
 
Example 6
Source Project: gcs   File: FeatureEditor.java    License: Mozilla Public License 2.0 5 votes vote down vote up
private void removeFeature() {
    JComponent parent = (JComponent) getParent();
    parent.remove(this);
    if (parent.getComponentCount() == 0) {
        parent.add(new NoFeature(mRow));
    }
    parent.revalidate();
    parent.repaint();
}
 
Example 7
private void refreshMenu() {
  if (menuItems != null && menuItems.length > 0) {
    firstIndex = Math.max(topFixedCount, firstIndex);
    firstIndex = Math.min(menuItems.length - bottomFixedCount - scrollCount, firstIndex);

    upItem.setEnabled(firstIndex > topFixedCount);
    downItem.setEnabled(firstIndex + scrollCount < menuItems.length - bottomFixedCount);

    menu.removeAll();
    for (int i = 0; i < topFixedCount; i++) {
      menu.add(menuItems[i]);
    }
    if (topFixedCount > 0) {
      menu.add(new JSeparator());
    }

    menu.add(upItem);
    for (int i = firstIndex; i < scrollCount + firstIndex; i++) {
      menu.add(menuItems[i]);
    }
    menu.add(downItem);

    if (bottomFixedCount > 0) {
      menu.add(new JSeparator());
    }
    for (int i = menuItems.length - bottomFixedCount; i < menuItems.length; i++) {
      menu.add(menuItems[i]);
    }

    JComponent parent = (JComponent) upItem.getParent();
    parent.revalidate();
    parent.repaint();
  }
}
 
Example 8
Source Project: gcs   File: SkillDefaultEditor.java    License: Mozilla Public License 2.0 5 votes vote down vote up
private void addDefault() {
    SkillDefault skillDefault = new SkillDefault(LAST_ITEM_TYPE, LAST_ITEM_TYPE.isSkillBased() ? "" : null, null, 0); //$NON-NLS-1$
    JComponent   parent       = (JComponent) getParent();
    parent.add(new SkillDefaultEditor(skillDefault));
    if (mDefault == null) {
        parent.remove(this);
    }
    parent.revalidate();
    parent.repaint();
    notifyActionListeners();
}
 
Example 9
Source Project: gcs   File: PrereqEditor.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent event) {
    String command = event.getActionCommand();
    if (CHANGE_BASE_TYPE.equals(command)) {
        Class<?> type = BASE_TYPES[mBaseTypeCombo.getSelectedIndex()];
        if (!mPrereq.getClass().equals(type)) {
            JComponent parent    = (JComponent) getParent();
            PrereqList list      = mPrereq.getParent();
            int        listIndex = list.getIndexOf(mPrereq);
            try {
                Prereq prereq;
                if (type == ContainedWeightPrereq.class) {
                    prereq = new ContainedWeightPrereq(list, mRow.getDataFile().defaultWeightUnits());
                } else {
                    prereq = (Prereq) type.getConstructor(PrereqList.class).newInstance(list);
                }
                if (prereq instanceof HasPrereq && mPrereq instanceof HasPrereq) {
                    ((HasPrereq) prereq).has(((HasPrereq) mPrereq).has());
                }
                list.add(listIndex, prereq);
                list.remove(mPrereq);
                parent.add(create(mRow, prereq, mDepth), UIUtilities.getIndexOf(parent, this));
            } catch (Exception exception) {
                // Shouldn't have a failure...
                exception.printStackTrace(System.err);
            }
            parent.remove(this);
            parent.revalidate();
            parent.repaint();
            ListPrereqEditor.setLastItemType(type);
        }
    } else if (CHANGE_HAS.equals(command)) {
        ((HasPrereq) mPrereq).has(((JComboBox<?>) event.getSource()).getSelectedIndex() == 0);
    } else {
        super.actionPerformed(event);
    }
}
 
Example 10
public static void setZoomingEnabled(JComponent chartUI, boolean enabled) {
    SimpleXYChart chart = (SimpleXYChart)chartUI.getClientProperty("chart"); // NOI18N
    
    if (chart.isZoomingEnabled() == enabled) return;
    else chart.setZoomingEnabled(enabled);
    
    JPanel sidePanel = (JPanel)chartUI.getClientProperty("sidePanel"); // NOI18N
    JPanel scrollerPanel = (JPanel)chartUI.getClientProperty("scrollerPanel"); // NOI18N
    
    if (enabled) {
        TransparentToolBar toolbar = new TransparentToolBar(false);
        for (Action action : chart.getActions()) toolbar.addItem(action);
        sidePanel.add(toolbar);
        
        JScrollBar scroller = chart.getScroller();
        scroller.setSize(scroller.getPreferredSize());
        scrollerPanel.add(scroller);
        chart.putClientProperty("scroller", scroller); // NOI18N
    } else {
        sidePanel.removeAll();
        scrollerPanel.removeAll();
        chart.putClientProperty("scroller", null); // NOI18N
    }
    
    sidePanel.setVisible(enabled);
    
    chartUI.doLayout();
    chartUI.repaint();
}
 
Example 11
Source Project: ChatGameFontificator   File: ComboMenuBar.java    License: The Unlicense 5 votes vote down vote up
public void updateScroll()
{
    List<JMenuItem> menuKeyList = getKeyList();

    // Keep the first index less than the total number available in the list (unfiltered) minus the length of the scroll count, and no lower than zero
    firstIndex = Math.min(firstIndex, menuKeyList.size() - SCROLL_COUNT);
    firstIndex = Math.max(firstIndex, 0);
    int lastIndex = firstIndex + Math.min(menuKeyList.size(), SCROLL_COUNT);

    int runningUnfilteredCount = 0;
    for (int i = 0; i < menuKeyList.size(); i++)
    {
        JMenuItem jmi = menuKeyList.get(i);
        MenuVisibilityStatus status = allMenuItems.get(jmi);
        final boolean inScrollBounds = !status.isFiltered() && runningUnfilteredCount >= firstIndex && runningUnfilteredCount < lastIndex;
        status.setOutOfScrollBounds(!inScrollBounds);
        if (!status.isFiltered())
        {
            runningUnfilteredCount++;
        }
    }

    mainMenu.getPopupMenu().removeAll();
    setMenuItemFilterVisibility();

    upItem.setEnabled(firstIndex > 0);
    mainMenu.getPopupMenu().add(upItem);
    List<JMenuItem> inBoundsScrollMenuFolders = getInBoundScrollMenuFolders();

    for (JMenuItem menuFolder : inBoundsScrollMenuFolders)
    {
        mainMenu.getPopupMenu().add(menuFolder);
    }
    downItem.setEnabled(lastIndex < runningUnfilteredCount);
    mainMenu.getPopupMenu().add(downItem);

    JComponent parent = (JComponent) upItem.getParent();
    parent.revalidate();
    parent.repaint();
}
 
Example 12
void repaintComponents()
{
  for (final JComponent comp : components) {
    comp.invalidate();
    comp.repaint();
  }
}
 
Example 13
Source Project: pumpernickel   File: AnimatedLayout.java    License: MIT License 5 votes vote down vote up
protected void layoutContainerImmediately(JComponent parent) {
	synchronized (parent.getTreeLock()) {
		Map<JComponent, Rectangle> destMap = getDestinationMap(parent);
		for (Entry<JComponent, Rectangle> entry : destMap.entrySet()) {
			entry.getKey().setBounds(entry.getValue());
		}
	}
	parent.repaint();
}
 
Example 14
Source Project: jmeter-plugins   File: GraphPanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *
 */
public void updateGui() {
    graphPanelObject.invalidateCache();
    JComponent selectedTab = (JComponent) getSelectedComponent();
    selectedTab.updateUI();
    selectedTab.repaint();
}
 
Example 15
Source Project: jclic   File: AbstractBox.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void repaint() {
  JComponent jc = getContainerResolve();
  if (jc != null)
    jc.repaint(getBorderBounds());
  if (hostedComponent != null)
    hostedComponent.repaint();
}
 
Example 16
Source Project: netbeans   File: ViewUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static void repaint(JComponent component, Rectangle2D r) {
    component.repaint((int)r.getX(), (int)r.getY(), (int)r.getWidth(), (int)r.getHeight());
}
 
Example 17
Source Project: Rails   File: HexMap.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Do only call this method if you are sure that a complete repaint is
 * needed!
 */
public synchronized void repaintAll(Rectangle r) {
    for (JComponent l : layers) {
        l.repaint(r);
    }
}
 
Example 18
Source Project: basicv2   File: BlockCaret.java    License: The Unlicense 4 votes vote down vote up
public void mouseClicked(MouseEvent e) {
	JComponent c = (JComponent) e.getComponent();
	c.repaint();
}
 
Example 19
Source Project: jclic   File: TextGrid.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void repaintCell(int px, int py) {
  JComponent jc = getContainerResolve();
  if (jc != null)
    jc.repaint(getCellBorderBounds(px, py));
}
 
Example 20
Source Project: pumpernickel   File: AbstractPanelUI.java    License: MIT License 4 votes vote down vote up
/**
 * Repaint all panels using this UI.
 */
protected void repaintInstalledPanels() {
	for (JComponent jc : getInstalledPanels()) {
		jc.repaint();
	}
}