Example usage for java.awt Component invalidate

List of usage examples for java.awt Component invalidate

Introduction

In this page you can find the example usage for java.awt Component invalidate.

Prototype

public void invalidate() 

Source Link

Document

Invalidates this component and its ancestors.

Usage

From source file:Main.java

public static void forceRevalidate(Component comp) {
    comp.invalidate();
    comp.validate();
    comp.repaint();
}

From source file:Main.java

public static void invalidateTree(java.awt.Component c) {
    c.invalidate();
    if (c instanceof java.awt.Container) {
        java.awt.Container container = (java.awt.Container) c;
        for (java.awt.Component component : container.getComponents()) {
            invalidateTree(component);/*  ww  w  .ja  va2s.c om*/
        }
    }
}

From source file:Main.java

private static void invalidateSubtreeRec(Component c) {
    if (c != null && c.isVisible()) {
        c.invalidate();
        if (c instanceof Container) {
            for (Component child : ((Container) c).getComponents()) {
                invalidateSubtreeRec(child);
            }/*from   w w  w . j  ava 2s . c om*/
        }
    }
}

From source file:Main.java

/**
 * A simple minded look and feel change: ask each node in the tree
 * to <code>updateUI()</code> -- that is, to initialize its UI property
 * with the current look and feel.// w ww  . j a  va 2  s .c  o m
 *
 * @param c UI component.
 */
public static void updateComponentTreeUI(Component c) {
    updateComponentTreeUI0(c);
    c.invalidate();
    c.validate();
    c.repaint();
}

From source file:Main.java

/**
 * Workaround for bug in swing invalidate/validate concept. Swing is caching
 * component sizes and clearing that cache once invalidate is called, which is
 * fine. But in case a validate is in progress and part of the ancestor tree
 * is already layouted based on old sizes then the caches are already set, but
 * the valid flag is still false. Therefore this method can be called which
 * will invalidate all ancestors *including* those that are still invalid in
 * order to clear all size caches. see also invalidateSubTree()
 *//*from   w  w  w.j  a  v a 2  s .c om*/
public static void invalidateAncestors(Component c) {
    if (c != null) {
        while (true) {
            c.invalidate();
            c = c.getParent();
            if (c == null) {
                break;
            }
            if (c instanceof JComponent && ((JComponent) c).isValidateRoot()) {
                break;
            }
        }
    }
}

From source file:edu.ku.brc.af.core.NavBox.java

/**
 * Refreshes - meaning it makes sure it is resized (layed out) and drawn.
 * @param nbi the box to refresh//w ww  .j a va2  s  . co m
 */
public static void refresh(final NavBoxItemIFace nbi) {
    if (nbi != null) {
        Component comp = nbi.getUIComponent();
        comp.invalidate();
        comp.doLayout();
        comp.setSize(comp.getPreferredSize());
        comp.repaint();
        log.debug("comp " + comp.getPreferredSize() + " " + comp.getSize()); //$NON-NLS-1$ //$NON-NLS-2$

        Container parentComp = nbi.getUIComponent().getParent();
        if (parentComp instanceof NavBox) {
            refresh((NavBox) parentComp);
        } else if (parentComp instanceof JScrollPane) {
            // this must be a scrollable NavBox;
            // let's get the actual NavBox
            // container heirarchy is NavBox -> JScrollPane -> NavBoxItem
            parentComp = parentComp.getParent().getParent();
            refresh((NavBox) parentComp);
        }
    }
}

From source file:cool.pandora.modeller.ui.BagInfoInputPane.java

/**
 * updateForms./*from   ww  w  . ja v a2s  . co  m*/
 *
 * @param bag DefaultBag
 */
public void updateForms(final DefaultBag bag) {

    verifyForms(bag);
    createTabbedUiComponentsWithForms();

    final java.awt.Component[] components = bagInfoForm.getControl().getComponents();
    for (final Component c : components) {
        c.invalidate();
        c.repaint();
    }
    bagInfoForm.getControl().invalidate();
    profileForm.getControl().invalidate();
    invalidate();
    repaint();

}

From source file:edu.ku.brc.af.prefs.PreferencesDlg.java

/**
 * @param comp/*  w  w w  .ja v  a2s  . com*/
 * @param oldSize
 */
protected void showAndResizePane(final Component comp, final Dimension oldSize) {
    mainPanel.remove(currentComp);

    currentComp.setVisible(false);
    mainPanel.add(comp, BorderLayout.CENTER);
    comp.invalidate();
    comp.validate();
    comp.invalidate();
    comp.doLayout();
    comp.repaint();
    doLayout();
    repaint();
    currentComp = comp;
    currentComp.setVisible(true);

    Dimension oldWinDim = getSize();
    Dimension winDim = getSize();
    winDim.width += currentComp.getPreferredSize().width - oldSize.width;
    winDim.width = Math.max(winDim.width, 400);
    winDim.height = Math.max(winDim.height, 250);

    Dimension pSize = prefsToolbar.getPreferredSize();
    winDim.width = Math.max(winDim.width, pSize.width + 30);

    if (winDim.equals(oldWinDim)) // needed because JGoodies doesn't want to relayout when it is the same size.
    {
        winDim.height += 2;
    }
    setSize(winDim);
    currentComp.setSize(new Dimension(currentComp.getPreferredSize().width, oldSize.height));

    // Not sure why this combination works
    mainPanel.invalidate();
    mainPanel.validate();
    mainPanel.invalidate();
    mainPanel.doLayout();
    mainPanel.repaint();

    invalidate();
    validate();
    invalidate();
    doLayout();

    doLayout();
    repaint();
    // to here

    ((PrefsPanelIFace) comp).setShadeColor(null);

    // Without Animation
    comp.setVisible(true);
    winDim.height += currentComp.getPreferredSize().height - oldSize.height;
    winDim.height = Math.max(winDim.height, 250);
    setSize(winDim);
}

From source file:edu.ku.brc.af.prefs.PreferencesDlg.java

@Override
public void showPanel(final String name) {
    if (StringUtils.isNotEmpty(name)) {
        Component comp = compsHash.get(name);
        if (comp == currentComp) {
            log.error(String.format("The pref pane by the name '%s' is was not found.", name));
            return;
        }//w  w w.  j  av a 2s .  c  o m

        if (false) {
            boolean makeVis = false;
            Dimension oldSize = null;
            if (currentComp != null) {
                oldSize = currentComp.getSize();
                mainPanel.remove(currentComp);

            } else {
                makeVis = true;
            }

            String hContext = prefPanelsHash.get(name).getHelpContext();
            if (StringUtils.isNotEmpty(hContext)) {
                HelpMgr.registerComponent(helpBtn, hContext);
            }

            if (comp != null) {
                comp.setVisible(makeVis);
                mainPanel.add(comp, BorderLayout.CENTER);
                comp.invalidate();
                doLayout();
                repaint();
                currentComp = comp;
                if (oldSize != null) {
                    Dimension winDim = getSize();
                    winDim.width += currentComp.getPreferredSize().width - oldSize.width;
                    winDim.width = Math.max(winDim.width, 400);
                    winDim.height = Math.max(winDim.height, 250);

                    Dimension pSize = prefsToolbar.getPreferredSize();
                    winDim.width = Math.max(winDim.width, pSize.width + 30);

                    setSize(winDim);
                    currentComp.setSize(new Dimension(currentComp.getPreferredSize().width, oldSize.height));

                    // With Animation
                    //startAnimation(this, comp, currentComp.getPreferredSize().height - oldSize.height, false);

                    ((PrefsPanelIFace) comp).setShadeColor(new Color(255, 255, 255, 255));

                    // Without Animation
                    comp.setVisible(true);
                    winDim.height += currentComp.getPreferredSize().height - oldSize.height;
                    winDim.height = Math.max(winDim.height, 250);
                    setSize(winDim);

                    new Timer(MILLI_SEC_DELAY, new FadeInAnimation(comp, 7)).start();
                }
            }
        } else {
            boolean makeVis = false;
            Dimension oldSize = null;
            if (currentComp != null) {
                oldSize = currentComp.getSize();

            } else {
                makeVis = true;
            }

            String hContext = prefPanelsHash.get(name).getHelpContext();
            if (StringUtils.isNotEmpty(hContext)) {
                HelpMgr.registerComponent(helpBtn, hContext);
            }

            if (comp != null) {
                if (currentComp == null) {
                    comp.setVisible(makeVis);
                    mainPanel.add(comp, BorderLayout.CENTER);
                    comp.invalidate();
                    doLayout();
                    repaint();
                    currentComp = comp;
                    return;
                }

                if (oldSize != null) {
                    ((PrefsPanelIFace) currentComp).setShadeColor(new Color(255, 255, 255, 0));

                    new Timer(MILLI_SEC_DELAY, new FadeOutAnimation(comp, oldSize, 12)).start();
                }
            }

        }
    }
}

From source file:com.monead.semantic.workbench.SemanticWorkbench.java

/**
 * Sets the mouse pointer. If the supplied parameter is true then the wait
 * cursor (usually an hourglass) is displayed. otherwise the system default
 * cursor is displayed./*from  w  w  w .  ja v a2s  . c o m*/
 * 
 * @param wait
 *          Whether to display the system default wait cursor
 */
private void setWaitCursor(boolean wait) {
    final JRootPane rootPane = getRootPane();
    final Component glassPane = rootPane.getGlassPane();

    if (wait) {
        final Cursor cursorWait = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
        rootPane.setCursor(cursorWait);
        glassPane.setCursor(cursorWait);
        glassPane.setVisible(true);
    } else {
        final Cursor cursorDefault = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
        glassPane.setVisible(false);
        glassPane.setCursor(cursorDefault);
        rootPane.setCursor(cursorDefault);
    }

    glassPane.invalidate();
    rootPane.validate();
}