Java Code Examples for java.awt.Container#setVisible()

The following examples show how to use java.awt.Container#setVisible() . 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: CustomPopupFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void doHide() {
    Container parent = contents.getParent();
    if (parent != null) {
        contents.getParent().remove (contents);
        parent.repaint(bounds.x, bounds.y, bounds.width, bounds.height);
        parent.setVisible(false);
    }
    //If doShow() was never called, we've modified the visibility
    //of the contents component, which could cause problems elsewhere
    contents.setVisible (true);
}
 
Example 2
Source File: CommitPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void displaySection(Container sectionPanel,
                            String initPanelMethodName) {
    if (sectionPanel.getComponentCount() == 0) {
        invokeInitPanelMethod(initPanelMethodName);
    }
    sectionPanel.setVisible(true);
    enlargeVerticallyAsNecessary();
}
 
Example 3
Source File: CommitPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void displaySection(Container sectionPanel,
                            String initPanelMethodName) {
    if (sectionPanel.getComponentCount() == 0) {
        invokeInitPanelMethod(initPanelMethodName);
    }
    sectionPanel.setVisible(true);
    enlargeVerticallyAsNecessary();
}
 
Example 4
Source File: Options.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
public static void loadOptions(final String name,
                               final Container component, final Properties properties) {

    if (ResourceLoader.isParent(JFrame.class, component.getClass())) {
        ((JFrame) component).setBounds(getRectangle(name,
                ((JFrame) component).getBounds(), properties));
    }

    if (ResourceLoader.isParent(JDialog.class, component.getClass())) {
        ((JDialog) component).setBounds(getRectangle(name,
                ((JDialog) component).getBounds(), properties));
    }
    if (ResourceLoader.isParent(RowFindPanel.class, component.getClass())) {
        component.setVisible(getBoolean(name + ".Visible",
                component.isVisible(), properties));
        ((RowFindPanel) component).getJCheckBox().setSelected(
                getBoolean(name + ".WO", ((RowFindPanel) component)
                        .getJCheckBox().isSelected(), properties));
    }

    for (int i = 0; i < component.getComponentCount(); i++) {
        if (ResourceLoader.isParent(JTable.class, component.getComponent(i)
                .getClass()))
            getJTableOptions(name + "_" + i,
                    (JTable) component.getComponent(i), properties);
        if (ResourceLoader.isParent(JSplitPane.class, component
                .getComponent(i).getClass())) {
            ((JSplitPane) component.getComponent(i))
                    .setDividerLocation(getInteger(name + "__" + i,
                            ((JSplitPane) component.getComponent(i))
                                    .getDividerLocation(), properties));

        }

        if (ResourceLoader.isParent(Container.class, component
                .getComponent(i).getClass()))
            loadOptions(name + "X" + i,
                    (Container) component.getComponent(i), properties);
    }
}
 
Example 5
Source File: JGlassPaneInternalFrameOverlapping.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void prepareControls() {
    JFrame frame = new JFrame("Glass Pane children test");
    frame.setLayout(null);

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new BorderLayout());
    super.propagateAWTControls(contentPane);

    Container glassPane = (Container) frame.getRootPane().getGlassPane();
    glassPane.setVisible(true);
    glassPane.setLayout(null);

    internalFrame = new JInternalFrame("Internal Frame", true);
    internalFrame.setBounds(50, 0, 200, 100);
    internalFrame.setVisible(true);
    glassPane.add(internalFrame);

    internalFrame.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            lwClicked = true;
        }
    });

    frame.setSize(300, 180);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
 
Example 6
Source File: JOptionPane.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Prompts the user for input in a blocking internal dialog where
 * the initial selection, possible selections, and all other
 * options can be specified. The user will able to choose from
 * <code>selectionValues</code>, where <code>null</code>
 * implies the user can input
 * whatever they wish, usually by means of a <code>JTextField</code>.
 * <code>initialSelectionValue</code> is the initial value to prompt
 * the user with. It is up to the UI to decide how best to represent
 * the <code>selectionValues</code>, but usually a
 * <code>JComboBox</code>, <code>JList</code>, or
 * <code>JTextField</code> will be used.
 *
 * @param parentComponent the parent <code>Component</code> for the dialog
 * @param message  the <code>Object</code> to display
 * @param title    the <code>String</code> to display in the dialog
 *          title bar
 * @param messageType the type of message to be displayed:
 *                  <code>ERROR_MESSAGE</code>, <code>INFORMATION_MESSAGE</code>,
 *                  <code>WARNING_MESSAGE</code>,
 *                  <code>QUESTION_MESSAGE</code>, or <code>PLAIN_MESSAGE</code>
 * @param icon     the <code>Icon</code> image to display
 * @param selectionValues an array of <code>Objects</code> that
 *                  gives the possible selections
 * @param initialSelectionValue the value used to initialize the input
 *                  field
 * @return user's input, or <code>null</code> meaning the user
 *          canceled the input
 */
public static Object showInternalInputDialog(Component parentComponent,
        Object message, String title, int messageType, Icon icon,
        Object[] selectionValues, Object initialSelectionValue) {
    JOptionPane pane = new JOptionPane(message, messageType,
            OK_CANCEL_OPTION, icon, null, null);
    pane.putClientProperty(PopupFactory_FORCE_HEAVYWEIGHT_POPUP,
            Boolean.TRUE);
    Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager().
            getFocusOwner();

    pane.setWantsInput(true);
    pane.setSelectionValues(selectionValues);
    pane.setInitialSelectionValue(initialSelectionValue);

    JInternalFrame dialog =
        pane.createInternalFrame(parentComponent, title);

    pane.selectInitialValue();
    dialog.setVisible(true);

    /* Since all input will be blocked until this dialog is dismissed,
     * make sure its parent containers are visible first (this component
     * is tested below).  This is necessary for JApplets, because
     * because an applet normally isn't made visible until after its
     * start() method returns -- if this method is called from start(),
     * the applet will appear to hang while an invisible modal frame
     * waits for input.
     */
    if (dialog.isVisible() && !dialog.isShowing()) {
        Container parent = dialog.getParent();
        while (parent != null) {
            if (parent.isVisible() == false) {
                parent.setVisible(true);
            }
            parent = parent.getParent();
        }
    }

    AWTAccessor.getContainerAccessor().startLWModal(dialog);

    if (parentComponent instanceof JInternalFrame) {
        try {
            ((JInternalFrame)parentComponent).setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

    if (fo != null && fo.isShowing()) {
        fo.requestFocus();
    }
    Object value = pane.getInputValue();

    if (value == UNINITIALIZED_VALUE) {
        return null;
    }
    return value;
}
 
Example 7
Source File: JOptionPane.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Prompts the user for input in a blocking internal dialog where
 * the initial selection, possible selections, and all other
 * options can be specified. The user will able to choose from
 * <code>selectionValues</code>, where <code>null</code>
 * implies the user can input
 * whatever they wish, usually by means of a <code>JTextField</code>.
 * <code>initialSelectionValue</code> is the initial value to prompt
 * the user with. It is up to the UI to decide how best to represent
 * the <code>selectionValues</code>, but usually a
 * <code>JComboBox</code>, <code>JList</code>, or
 * <code>JTextField</code> will be used.
 *
 * @param parentComponent the parent <code>Component</code> for the dialog
 * @param message  the <code>Object</code> to display
 * @param title    the <code>String</code> to display in the dialog
 *          title bar
 * @param messageType the type of message to be displayed:
 *                  <code>ERROR_MESSAGE</code>, <code>INFORMATION_MESSAGE</code>,
 *                  <code>WARNING_MESSAGE</code>,
 *                  <code>QUESTION_MESSAGE</code>, or <code>PLAIN_MESSAGE</code>
 * @param icon     the <code>Icon</code> image to display
 * @param selectionValues an array of <code>Objects</code> that
 *                  gives the possible selections
 * @param initialSelectionValue the value used to initialize the input
 *                  field
 * @return user's input, or <code>null</code> meaning the user
 *          canceled the input
 */
public static Object showInternalInputDialog(Component parentComponent,
        Object message, String title, int messageType, Icon icon,
        Object[] selectionValues, Object initialSelectionValue) {
    JOptionPane pane = new JOptionPane(message, messageType,
            OK_CANCEL_OPTION, icon, null, null);
    pane.putClientProperty(PopupFactory_FORCE_HEAVYWEIGHT_POPUP,
            Boolean.TRUE);
    Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager().
            getFocusOwner();

    pane.setWantsInput(true);
    pane.setSelectionValues(selectionValues);
    pane.setInitialSelectionValue(initialSelectionValue);

    JInternalFrame dialog =
        pane.createInternalFrame(parentComponent, title);

    pane.selectInitialValue();
    dialog.setVisible(true);

    /* Since all input will be blocked until this dialog is dismissed,
     * make sure its parent containers are visible first (this component
     * is tested below).  This is necessary for JApplets, because
     * because an applet normally isn't made visible until after its
     * start() method returns -- if this method is called from start(),
     * the applet will appear to hang while an invisible modal frame
     * waits for input.
     */
    if (dialog.isVisible() && !dialog.isShowing()) {
        Container parent = dialog.getParent();
        while (parent != null) {
            if (parent.isVisible() == false) {
                parent.setVisible(true);
            }
            parent = parent.getParent();
        }
    }

    AWTAccessor.getContainerAccessor().startLWModal(dialog);

    if (parentComponent instanceof JInternalFrame) {
        try {
            ((JInternalFrame)parentComponent).setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

    if (fo != null && fo.isShowing()) {
        fo.requestFocus();
    }
    Object value = pane.getInputValue();

    if (value == UNINITIALIZED_VALUE) {
        return null;
    }
    return value;
}
 
Example 8
Source File: PluggableTreeTableView.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
protected void fireItemStateChanged(ItemEvent e) {
    Container container = getPluginContainer();
    container.setVisible(e.getStateChange() == ItemEvent.SELECTED);
    checkVisibility((JComponent)container.getParent());
}
 
Example 9
Source File: Swing.java    From pdfxtk with Apache License 2.0 4 votes vote down vote up
public static void startModal(javax.swing.JInternalFrame f) {
   synchronized(f) {
     /* Since all input will be blocked until this dialog is dismissed,
      * make sure its parent containers are visible first (this component
      * is tested below).  This is necessary for JApplets, because
      * because an applet normally isn't made visible until after its
      * start() method returns -- if this method is called from start(),
      * the applet will appear to hang while an invisible modal frame
      * waits for input.
      */
     
     if (f.isVisible() && !f.isShowing()) {
Container parent = f.getParent();
while (parent != null) {
  if (parent.isVisible() == false) {
    parent.setVisible(true);
  }
  parent = parent.getParent();
}
     }

     try {
if (SwingUtilities.isEventDispatchThread()) {
  EventQueue theQueue = f.getToolkit().getSystemEventQueue();
  while (f.isVisible()) {
    // This is essentially the body of EventDispatchThread
    AWTEvent event = theQueue.getNextEvent();
    Object src = event.getSource();
    // can't call theQueue.dispatchEvent, so I pasted it's body here
    /*if (event instanceof ActiveEvent) {
      ((ActiveEvent) event).dispatch();
      } else */ if (src instanceof Component) {
	((Component) src).dispatchEvent(event);
      } else if (src instanceof MenuComponent) {
	((MenuComponent) src).dispatchEvent(event);
      } else {
	System.err.println("unable to dispatch event: " + event);
      }
  }
} else
  while (f.isVisible())
    f.wait();
     } catch(InterruptedException e){}
   }
 }