Example usage for javax.swing JFrame setJMenuBar

List of usage examples for javax.swing JFrame setJMenuBar

Introduction

In this page you can find the example usage for javax.swing JFrame setJMenuBar.

Prototype

@BeanProperty(bound = false, hidden = true, description = "The menubar for accessing pulldown menus from this frame.")
public void setJMenuBar(final JMenuBar menubar) 

Source Link

Document

Sets the menubar for this frame.

Usage

From source file:components.MenuSelectionManagerDemo.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread./*from  w ww .  j av  a  2s . c  o m*/
 */
private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("MenuSelectionManagerDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Create and set up the content pane.
    MenuSelectionManagerDemo demo = new MenuSelectionManagerDemo();
    frame.setJMenuBar(demo.createMenuBar());
    frame.setContentPane(demo.createContentPane());

    //Display the window.
    frame.setSize(450, 260);
    frame.setVisible(true);
}

From source file:TextCutPaste.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *///w w w  .  j a v a  2 s.c  o  m
private static void createAndShowGUI() {
    // Create and set up the window.
    JFrame frame = new JFrame("TextCutPaste");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create and set up the menu bar and content pane.
    TextCutPaste demo = new TextCutPaste();
    frame.setJMenuBar(demo.createMenuBar());
    demo.setOpaque(true); // content panes must be opaque
    frame.setContentPane(demo);

    // Display the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:MenuSelectionManagerDemo.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *///from w ww.  j  av a  2s. c  o m
private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);

    //Create and set up the window.
    JFrame frame = new JFrame("MenuSelectionManagerDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Create and set up the content pane.
    MenuSelectionManagerDemo demo = new MenuSelectionManagerDemo();
    frame.setJMenuBar(demo.createMenuBar());
    frame.setContentPane(demo.createContentPane());

    //Display the window.
    frame.setSize(450, 260);
    frame.setVisible(true);
}

From source file:DragColorTextFieldDemo.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *//*from  w ww  .  j  av a  2 s .  c o m*/
private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);

    //Create and set up the window.
    JFrame frame = new JFrame("DragColorTextFieldDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Create and set up the menu bar and content pane.
    DragColorTextFieldDemo demo = new DragColorTextFieldDemo();
    frame.setJMenuBar(demo.createMenuBar());
    demo.setOpaque(true); //content panes must be opaque
    frame.setContentPane(demo);

    //Display the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:ListCutPaste.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *///www  .  j a  va 2s  . c  o m
private static void createAndShowGUI() {
    // Create and set up the window.
    JFrame frame = new JFrame("ListCutPaste");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create and set up the menu bar and content pane.
    ListCutPaste demo = new ListCutPaste();
    frame.setJMenuBar(demo.createMenuBar());
    demo.setOpaque(true); // content panes must be opaque
    frame.setContentPane(demo);

    // Display the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:DragPictureDemo2.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *//* www  .  j a v  a 2 s. c  o m*/
private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);

    //Create and set up the window.
    JFrame frame = new JFrame("DragPictureDemo2");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Create and set up the menu bar and content pane.
    DragPictureDemo2 demo = new DragPictureDemo2();
    frame.setJMenuBar(demo.createMenuBar());
    demo.setOpaque(true); //content panes must be opaque
    frame.setContentPane(demo);

    //Display the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:TopLevelDemo.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *//*  ww w  . jav a 2  s.  c o  m*/
private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);

    //Create and set up the window.
    JFrame frame = new JFrame("TopLevelDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Create the menu bar. Make it have a cyan background.
    JMenuBar cyanMenuBar = new JMenuBar();
    cyanMenuBar.setOpaque(true);
    cyanMenuBar.setBackground(Color.cyan);
    cyanMenuBar.setPreferredSize(new Dimension(200, 20));

    //Create a yellow label to put in the content pane.
    JLabel yellowLabel = new JLabel();
    yellowLabel.setOpaque(true);
    yellowLabel.setBackground(Color.yellow);
    yellowLabel.setPreferredSize(new Dimension(200, 180));

    //Set the menu bar and add the label to the content pane.
    frame.setJMenuBar(cyanMenuBar);
    frame.getContentPane().add(yellowLabel, BorderLayout.CENTER);

    //Display the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:components.TopLevelDemo.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread.//from  w ww  . j  a v a2s. c o m
 */
private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("TopLevelDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Create the menu bar.  Make it have a green background.
    JMenuBar greenMenuBar = new JMenuBar();
    greenMenuBar.setOpaque(true);
    greenMenuBar.setBackground(new Color(154, 165, 127));
    greenMenuBar.setPreferredSize(new Dimension(200, 20));

    //Create a yellow label to put in the content pane.
    JLabel yellowLabel = new JLabel();
    yellowLabel.setOpaque(true);
    yellowLabel.setBackground(new Color(248, 213, 131));
    yellowLabel.setPreferredSize(new Dimension(200, 180));

    //Set the menu bar and add the label to the content pane.
    frame.setJMenuBar(greenMenuBar);
    frame.getContentPane().add(yellowLabel, BorderLayout.CENTER);

    //Display the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:components.GlassPaneDemo.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread.//from w  w w  .  j ava  2 s  .c om
 */
private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("GlassPaneDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Start creating and adding components.
    JCheckBox changeButton = new JCheckBox("Glass pane \"visible\"");
    changeButton.setSelected(false);

    //Set up the content pane, where the "main GUI" lives.
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new FlowLayout());
    contentPane.add(changeButton);
    contentPane.add(new JButton("Button 1"));
    contentPane.add(new JButton("Button 2"));

    //Set up the menu bar, which appears above the content pane.
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Menu");
    menu.add(new JMenuItem("Do nothing"));
    menuBar.add(menu);
    frame.setJMenuBar(menuBar);

    //Set up the glass pane, which appears over both menu bar
    //and content pane and is an item listener on the change
    //button.
    myGlassPane = new MyGlassPane(changeButton, menuBar, frame.getContentPane());
    changeButton.addItemListener(myGlassPane);
    frame.setGlassPane(myGlassPane);

    //Show the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:GlassPaneDemo.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *//*from  w  w  w  .  j a va  2  s  .c  om*/
private static void createAndShowGUI() {
    // Create and set up the window.
    JFrame frame = new JFrame("GlassPaneDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Start creating and adding components.
    JCheckBox changeButton = new JCheckBox("Glass pane \"visible\"");
    changeButton.setSelected(false);

    // Set up the content pane, where the "main GUI" lives.
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new FlowLayout());
    contentPane.add(changeButton);
    contentPane.add(new JButton("Button 1"));
    contentPane.add(new JButton("Button 2"));

    // Set up the menu bar, which appears above the content pane.
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Menu");
    menu.add(new JMenuItem("Do nothing"));
    menuBar.add(menu);
    frame.setJMenuBar(menuBar);

    // Set up the glass pane, which appears over both menu bar
    // and content pane and is an item listener on the change
    // button.
    myGlassPane = new MyGlassPane(changeButton, menuBar, frame.getContentPane());
    changeButton.addItemListener(myGlassPane);
    frame.setGlassPane(myGlassPane);

    // Show the window.
    frame.pack();
    frame.setVisible(true);
}