Java JRootPane
Java JRootPane
Java JRootPane
Nested Classes
Fields
protected defaultButton The button that gets activated when the pane
Container has the focus and a UI-specific action like
pressing the Enter key occurs.
protected glassPane The glass pane that overlays the menu bar and
Component content pane, so it can intercept mouse
movements and such.
static int ERROR_DIALOG Constant used for the windowDecorationStyle
property.
Constructor
Constructor Description
Useful Methods
JRootPane Example
1. import javax.swing.JButton;
2. import javax.swing.JFrame;
3. import javax.swing.JMenu;
4. import javax.swing.JMenuBar;
5. import javax.swing.JRootPane;
6.
7. public class JRootPaneExample {
8. public static void main(String[] args) {
9. JFrame f = new JFrame();
10. f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
11. JRootPane root = f.getRootPane();
12.
13. // Create a menu bar
14. JMenuBar bar = new JMenuBar();
15. JMenu menu = new JMenu("File");
16. bar.add(menu);
17. menu.add("Open");
18. menu.add("Close");
19. root.setJMenuBar(bar);
20.
21. // Add a button to the content pane
22. root.getContentPane().add(new JButton("Press Me"));
23.
24. // Display the UI
25. f.pack();
26. f.setVisible(true);
27. }
28. }
Output