Example usage for java.awt Component setVisible

List of usage examples for java.awt Component setVisible

Introduction

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

Prototype

public void setVisible(boolean b) 

Source Link

Document

Shows or hides this component depending on the value of parameter b .

Usage

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;
        }/*from  w w  w  .j ava2 s .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:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Centers the specified component on the parent and then makes it visible.
 * This method is mainly useful for windows, frames and dialogs. 
 * /*from w  w  w .j  av a  2s. c  o  m*/
 * @param parent    The visible parent.
  * @param child     The child to display.
 */
public static void centerAndShow(Component parent, Component child) {
    if (parent == null || child == null)
        return;
    Rectangle bounds = parent.getBounds();
    Rectangle ed = child.getBounds();
    child.setLocation(bounds.x + (bounds.width - ed.width) / 2, bounds.y + (bounds.height - ed.height) / 2);
    child.setVisible(true);
}

From source file:edu.ku.brc.ui.UIRegistry.java

/**
 * Clears the GlassPane, meaning it sets the mainComp visible again and sets the GlassPane to be hidden.
 *//*from w  w  w. ja v  a2  s .c om*/
public synchronized static void clearGlassPaneMsg() {
    Component mainComp = UIRegistry.get(UIRegistry.MAINPANE);
    if (mainComp != null && getGlassPane() != null && getGlassPane().isVisible()) {
        getGlassPane().setMaskingEvents(false);
        getGlassPane().setVisible(false);
        mainComp.setVisible(true);
        mainComp.repaint();

        Frame frame = (JFrame) get(FRAME);
        frame.setBounds(frameRect);
    }
    showingGlassPane = false;
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Sets the location of the specified child relative to the location
 * of the specified parent and then makes it visible.
 * This method is mainly useful for windows, frames and dialogs. 
 * //ww w  . j  a  v  a2  s. co m
 * @param parent    The visible parent.
 * @param child     The child to display.
 */
public static void setLocationRelativeTo(Component parent, Component child) {
    if (parent == null || child == null)
        return;
    int x = parent.getX() + parent.getWidth();
    int y = parent.getY();
    int childWidth = child.getWidth();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    if (x + childWidth > screenSize.getWidth()) {
        if (childWidth < parent.getX())
            x = parent.getX() - childWidth;
        else
            x = (int) (screenSize.getWidth() - childWidth);
    }
    child.setLocation(x, y);
    child.setVisible(true);
}

From source file:freemind.controller.Controller.java

public void setLeftToolbarVisible(boolean visible) {
    leftToolbarVisible = visible;//w  ww . ja v  a  2s  . c  om
    if (getMode() == null) {
        return;
    }
    final Component leftToolBar = getModeController().getLeftToolBar();
    if (leftToolBar != null) {
        leftToolBar.setVisible(leftToolbarVisible);
        ((JComponent) leftToolBar.getParent()).revalidate();
    }
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Sets the location of the specified child relative to the passed 
 * bounds./*  w  w w  .j a  v  a  2 s. c om*/
 * This method is mainly useful for windows, frames and dialogs. 
 * 
 * @param parentBounds  The bounds of the parent.
 * @param child        The child to display.
 */
public static void setLocationRelativeTo(Rectangle parentBounds, Component child) {
    if (child == null)
        return;
    if (parentBounds == null)
        parentBounds = new Rectangle(0, 0, 5, 5);

    int x = parentBounds.x + parentBounds.width;
    int y = parentBounds.y;
    int childWidth = child.getWidth();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    if (x + childWidth > screenSize.getWidth()) {
        if (childWidth < parentBounds.x)
            x = parentBounds.x - childWidth;
        else
            x = (int) (screenSize.getWidth() - childWidth);
    }
    child.setLocation(x, y);
    child.setVisible(true);
}

From source file:freemind.controller.Controller.java

public void afterMapModuleChange(MapModule oldMapModule, Mode oldMode, MapModule newMapModule, Mode newMode) {
    ModeController newModeController;// www. ja  va  2s .  c  o m
    if (newMapModule != null) {
        getFrame().setView(newMapModule.getView());
        setAllActions(true);
        if ((getView().getSelected() == null)) {
            moveToRoot();
        }
        lastOpened.mapOpened(newMapModule);
        ((MainToolBar) getToolbar()).setZoomComboBox(newMapModule.getView().getZoom());
        // old
        //            obtainFocusForSelected();
        newModeController = newMapModule.getModeController();
        newModeController.startupController();
        newModeController.setVisible(true);
        // old
        //            obtainFocusForSelected();
    } else {
        newModeController = newMode.getDefaultModeController();
        getFrame().setView(null);
        setAllActions(false);
    }
    setTitle();
    JToolBar newToolBar = newModeController.getModeToolBar();
    if (newToolBar != null) {
        toolbar.add(newToolBar);
        newToolBar.repaint();
    }
    /* new left toolbar. */
    Component newLeftToolBar = newModeController.getLeftToolBar();
    if (newLeftToolBar != null) {
        getFrame().getContentPane().add(newLeftToolBar, BorderLayout.WEST);
        if (leftToolbarVisible) {
            newLeftToolBar.setVisible(true);
            newLeftToolBar.repaint();
        } else {
            newLeftToolBar.setVisible(false);
        }
    }
    toolbar.validate();
    toolbar.repaint();
    MenuBar menuBar = getFrame().getFreeMindMenuBar();
    menuBar.updateMenus(newModeController);
    menuBar.revalidate();
    menuBar.repaint();
    // new
    obtainFocusForSelected();
}

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

/**
 * @param comp/*from  w w  w  .  jav a2s. c  om*/
 * @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:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Sets the location of the specified child relative to the location
 * of the specified parent and then makes it visible, and size to fill window.
 * This method is mainly useful for windows, frames and dialogs. 
 * //from w w  w.  j  a  va  2  s .  c  om
 * @param parentBounds    The bounds of the visible parent.
 * @param child     The child to display.
 * @param max      The maximum size of the window.
 */
public static void setLocationRelativeToAndSizeToWindow(Rectangle parentBounds, Component child,
        Dimension max) {
    if (child == null)
        return;
    if (parentBounds == null)
        parentBounds = new Rectangle(0, 0, 5, 5);
    if (max == null)
        max = new Dimension(5, 5);
    int x = (int) (parentBounds.getX() + parentBounds.getWidth());
    int y = (int) parentBounds.getY();
    int childWidth = child.getWidth();
    int childHeight = child.getHeight();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    if (x + childWidth > screenSize.getWidth()) {
        if (childWidth < parentBounds.getX())
            x = (int) (parentBounds.getX()) - childWidth;
        else
            x = (int) (screenSize.getWidth() - childWidth);
    }
    child.setLocation(x, y);
    int newHeight = (int) screenSize.getHeight() - y - 10;
    int newWidth = (int) screenSize.getWidth() - x - 10;

    if (newWidth > childWidth)
        childWidth = newWidth;
    if (newHeight > childHeight)
        childHeight = newHeight;

    if (childWidth > max.getWidth())
        childWidth = (int) max.getWidth();
    if (childHeight > max.getHeight())
        childHeight = (int) max.getHeight();

    child.setSize(childWidth, childHeight);
    child.setVisible(true);
}

From source file:self.philbrown.javaQuery.$.java

/**
 * Sets the visibility of the current selection to {@link View#VISIBLE}
 * @return this/* w w  w  . j ava  2s  . c  om*/
 */
public $ hide() {
    for (Component view : views) {
        view.setVisible(true);
    }
    return this;
}