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

The following examples show how to use javax.swing.JComponent#repaint() . 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 File: GridPanel.java    From Rails with 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
Source File: PluggableTreeTableView.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: SkillDefaultEditor.java    From gcs with 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 4
Source File: AnimatedLayout.java    From pumpernickel with 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 5
Source File: DefaultSwingBundleDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void repaintComponents()
{
  for (final JComponent comp : components) {
    comp.invalidate();
    comp.repaint();
  }
}
 
Example 6
Source File: ComboMenuBar.java    From ChatGameFontificator with 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 7
Source File: SimpleXYChartUtils.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
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 8
Source File: PrereqEditor.java    From gcs with 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 9
Source File: DefaultSwingBundleDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void repaintComponents()
{
  synchronized (components) {
    for (final JComponent comp : components) {
      comp.invalidate();
      comp.repaint();
    }
  }
}
 
Example 10
Source File: GraphPanel.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
public void updateGui() {
    graphPanelObject.invalidateCache();
    JComponent selectedTab = (JComponent) getSelectedComponent();
    selectedTab.updateUI();
    selectedTab.repaint();
}
 
Example 11
Source File: MenuScroller.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
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 12
Source File: FeatureEditor.java    From gcs with 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 13
Source File: DefaultSwingBundleDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void repaintComponents()
{
  synchronized (components) {
    for (final JComponent comp : components) {
      comp.invalidate();
      comp.repaint();
    }
  }
}
 
Example 14
Source File: GridPanel.java    From Rails with 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 15
Source File: AbstractBox.java    From jclic with 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 File: TextGrid.java    From jclic with 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 17
Source File: AbstractPanelUI.java    From pumpernickel with MIT License 4 votes vote down vote up
/**
 * Repaint all panels using this UI.
 */
protected void repaintInstalledPanels() {
	for (JComponent jc : getInstalledPanels()) {
		jc.repaint();
	}
}
 
Example 18
Source File: BlockCaret.java    From basicv2 with The Unlicense 4 votes vote down vote up
public void mouseClicked(MouseEvent e) {
	JComponent c = (JComponent) e.getComponent();
	c.repaint();
}
 
Example 19
Source File: HexMap.java    From Rails with 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 20
Source File: ViewUtils.java    From netbeans with 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());
}