Example usage for javax.swing JComponent getRootPane

List of usage examples for javax.swing JComponent getRootPane

Introduction

In this page you can find the example usage for javax.swing JComponent getRootPane.

Prototype

@BeanProperty(bound = false)
public JRootPane getRootPane() 

Source Link

Document

Returns the JRootPane ancestor for this component.

Usage

From source file:Main.java

/**
 * i seperated it in different method to avoid affecting other components.
 *
 * @param comp/*w  w w  .  j  a v a2 s.  c  o  m*/
 *            the comp
 */
public static void packJFrameWindow(final JComponent comp) {
    if (comp.getRootPane() != null) {
        final Container cont = comp.getRootPane().getParent();
        if (cont instanceof JFrame) {
            ((JFrame) cont).pack();
            ((JFrame) cont).setLocationRelativeTo(null);
        }
    }
}

From source file:Main.java

/**
 * Close panel dialog./*from ww  w. ja va2 s  .c om*/
 *
 * @param comp
 *            the comp
 */
public static void closePanelDialog(final JComponent comp) {
    if (comp.getRootPane() != null) {
        final Container cont = comp.getRootPane().getParent();
        if (cont != null) {
            if (cont instanceof JDialog) {
                ((JDialog) cont).dispose();
            }
        }
    }
}

From source file:Main.java

/**
 * Pack window./*from  w  ww.  j  a  v a 2  s .c  o m*/
 *
 * @param comp
 *            the comp
 */
public static void packWindow(final JComponent comp) {

    if (comp.getRootPane() != null) {
        final Container cont = comp.getRootPane().getParent();
        if (cont != null) {
            if (cont instanceof JDialog) {
                ((JDialog) cont).pack();
                ((JDialog) cont).setLocationRelativeTo(null);
            }
        }
    }
}

From source file:Main.java

private static Window getWindow(final JComponent comp) {
    if (comp.getRootPane() != null) {
        final Container cont = comp.getRootPane().getParent();
        if (cont != null) {
            if (cont instanceof Window) {
                return (Window) cont;
            }/*from w  w  w  . jav a  2s. co m*/
        }
    }
    return null;
}

From source file:Main.java

/**
 * Initialises the {@link JDialog} for the {@link JComponent}.
 * /*from ww  w  .  j av a  2  s.c  o  m*/
 * @param dialog
 * @param component
 * @param parentComponent
 */
private static void initDialog(final JDialog dialog, final JComponent component,
        final Component parentComponent) {
    dialog.setResizable(true);
    dialog.setComponentOrientation(component.getComponentOrientation());
    Container contentPane = dialog.getContentPane();

    contentPane.setLayout(new BorderLayout());
    contentPane.add(component, BorderLayout.CENTER);

    final int buttonWidth = 75;

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(2, 4, 4, 4));

    buttonPanel.add(Box.createHorizontalGlue());

    @SuppressWarnings("serial")
    final Action closeAction = new AbstractAction("Close") {
        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    };

    final JButton button = new JButton(closeAction);
    fixWidth(button, buttonWidth);
    buttonPanel.add(button);

    contentPane.add(buttonPanel, BorderLayout.SOUTH);

    if (JDialog.isDefaultLookAndFeelDecorated()) {
        boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations();
        if (supportsWindowDecorations) {
            dialog.setUndecorated(true);
            component.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
        }
    }
    dialog.pack();
    dialog.setLocationRelativeTo(parentComponent);
    WindowAdapter adapter = new WindowAdapter() {
        //         private boolean gotFocus = false;
        public void windowClosing(WindowEvent we) {
            fireAction(we.getSource(), closeAction, "close");
        }
    };
    dialog.addWindowListener(adapter);
    dialog.addWindowFocusListener(adapter);
}

From source file:tk.tomby.tedit.core.ThreadSafeRepaintManager.java

/**
 * DOCUMENT ME!//w  w  w  . j av a 2  s .  c  o m
 *
 * @param c DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
private boolean isRootShowing(JComponent c) {
    return (c.getRootPane() != null) && c.getRootPane().isShowing();
}