Example usage for javax.swing JMenuBar setPreferredSize

List of usage examples for javax.swing JMenuBar setPreferredSize

Introduction

In this page you can find the example usage for javax.swing JMenuBar setPreferredSize.

Prototype

@BeanProperty(preferred = true, description = "The preferred size of the component.")
public void setPreferredSize(Dimension preferredSize) 

Source Link

Document

Sets the preferred size of this component.

Usage

From source file:TopLevelDemo.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() {
    //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.//  w  w w.j  av 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:savant.view.swing.Savant.java

private void initHiddenShortcuts() {
    JMenuBar hiddenBar = new JMenuBar();
    hiddenBar.setSize(new Dimension(0, 0));
    hiddenBar.setMaximumSize(new Dimension(0, 0));
    hiddenBar.setPreferredSize(new Dimension(0, 0));

    JMenuItem hiddenBookmarkPrev = new JMenuItem("");
    hiddenBookmarkPrev.setAccelerator(//from ww w .j  a va 2  s . co  m
            javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_9, MiscUtils.MENU_MASK));
    hiddenBookmarkPrev.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (favoriteSheet != null) {
                favoriteSheet.goToPreviousBookmark();
            }
        }
    });

    JMenuItem hiddenBookmarkNext = new JMenuItem("");
    hiddenBookmarkNext.setAccelerator(
            javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_0, MiscUtils.MENU_MASK));
    hiddenBookmarkNext.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (favoriteSheet != null) {
                favoriteSheet.goToNextBookmark();
            }
        }
    });

    hiddenBar.add(hiddenBookmarkPrev);
    hiddenBar.add(hiddenBookmarkNext);
    this.add(hiddenBar);
}