Another example of interacting with the root pane : RootPane « Swing JFC « Java






Another example of interacting with the root pane

Another example of interacting with the root pane
 
/*
Java Swing, 2nd Edition
By Marc Loy, Robert Eckstein, Dave Wood, James Elliott, Brian Cole
ISBN: 0-596-00408-7
Publisher: O'Reilly 
*/
// RootExample2.java
//Another example of interacting with the root pane. We set the menubar
//for the frame directly through the root pane in this example.
//

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JRootPane;

public class RootExample2 {
  public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JRootPane root = f.getRootPane();

    // Create a menu bar
    JMenuBar bar = new JMenuBar();
    JMenu menu = new JMenu("File");
    bar.add(menu);
    menu.add("Open");
    menu.add("Close");
    root.setJMenuBar(bar);

    // Add a button to the content pane
    root.getContentPane().add(new JButton("Hello World"));

    // Display the UI
    f.pack();
    f.setVisible(true);
  }
}

           
         
  








Related examples in the same category

1.Interact directly with the JRootPane of a JFrame
2.Make a JFrame looks like a JDialog
3.An example of interacting directly with the JRootPane of a JFrameAn example of interacting directly with the JRootPane of a JFrame
4.No direct interaction with JRootPaneNo direct interaction with JRootPane