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:self.philbrown.javaQuery.$.java

/**
 * Sets the visibility of this {@link #view} to {@link View#INVISIBLE}
 * @return this/*from  ww  w.  j a v  a2s.  c o m*/
 */
public $ show() {
    for (Component view : views) {
        view.setVisible(false);
    }
    return this;
}

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

/**
 * Writes a string message into the BufferedImage on GlassPane and sets the main component's visibility to false and
 * shows the GlassPane./*from   w ww .ja v  a  2 s. c  om*/
 * @param msg the message
 * @param pointSize the Font point size for the message to be writen in
 */
public static GhostGlassPane writeGlassPaneMsg(final String msg, final int pointSize) {
    GhostGlassPane glassPane = getGlassPane();
    if (glassPane != null) {
        glassPane.finishDnD();
    }

    glassPane.setMaskingEvents(true);

    Component mainComp = get(MAINPANE);
    if (mainComp != null && glassPane != null) {
        JFrame frame = (JFrame) get(FRAME);
        frameRect = frame.getBounds();

        int y = 0;
        JMenuBar menuBar = null;
        Dimension size = mainComp.getSize();
        if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) {
            menuBar = frame.getJMenuBar();
            size.height += menuBar.getSize().height;
            y += menuBar.getSize().height;
        }
        BufferedImage buffer = getGlassPaneBufferedImage(size.width, size.height);
        Graphics2D g2 = buffer.createGraphics();
        if (menuBar != null) {
            menuBar.paint(g2);
        }
        g2.translate(0, y);
        mainComp.paint(g2);
        g2.translate(0, -y);

        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(new Color(255, 255, 255, 128));
        g2.fillRect(0, 0, size.width, size.height);

        g2.setFont(new Font((new JLabel()).getFont().getName(), Font.BOLD, pointSize));
        FontMetrics fm = g2.getFontMetrics();

        int tw = fm.stringWidth(msg);
        int th = fm.getHeight();
        int tx = (size.width - tw) / 2;
        int ty = (size.height - th) / 2;

        int expand = 20;
        int arc = expand * 2;
        g2.setColor(Color.WHITE);
        g2.fillRoundRect(tx - (expand / 2), ty - fm.getAscent() - (expand / 2), tw + expand, th + expand, arc,
                arc);

        g2.setColor(Color.DARK_GRAY);
        g2.drawRoundRect(tx - (expand / 2), ty - fm.getAscent() - (expand / 2), tw + expand, th + expand, arc,
                arc);

        g2.setColor(Color.BLACK);
        g2.drawString(msg, tx, ty);
        g2.dispose();

        glassPane.setImage(buffer);
        glassPane.setPoint(new Point(0, 0), GhostGlassPane.ImagePaintMode.ABSOLUTE);
        glassPane.setOffset(new Point(0, 0));

        glassPane.setVisible(true);
        mainComp.setVisible(false);

        //Using paintImmediately fixes problems with glass pane not showing, such as for workbench saves initialed
        //during workbench or app shutdown. Don't know if there is a better way to fix it.
        //glassPane.repaint();
        glassPane.paintImmediately(glassPane.getBounds());
        showingGlassPane = true;
    }

    return glassPane;
}

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./*  w ww  .jav a 2s  .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();
}