FileDocCategorySizeDatePackage
RootExample2.javaAPI DocExample610Mon Nov 09 12:45:54 GMT 1998None

RootExample2.java

// RootExample2.java
//
import javax.swing.*;
import java.awt.*;

public class RootExample2 {
  public static void main(String[] args) {
    JFrame f = new JFrame();
    f.addWindowListener(new BasicWindowMonitor());
    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);
  }
}