Java Code Examples for javax.swing.JFrame.setJMenuBar()

The following are Jave code examples for showing how to use setJMenuBar() of the javax.swing.JFrame class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: marathonv5   File: PopupMenuDemoX.java   View Source Code Vote up 6 votes
/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 */
private static void createAndShowGUI() {
    // Create and set up the window.
    JFrame frame = new JFrame("PopupMenuDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create/set menu bar and content pane.
    PopupMenuDemoX demo = new PopupMenuDemoX();
    frame.setJMenuBar(demo.createMenuBar());
    frame.setContentPane(demo.createContentPane());

    // Create and set up the popup menu.
    demo.createPopupMenu();

    // Display the window.
    frame.setSize(450, 260);
    frame.setVisible(true);
}
 
Example 2
Project: openjdk-jdk10   File: CloseOnMouseClickPropertyTest.java   View Source Code Vote up 6 votes
private static void createAndShowGUI(TestItem testItem) {

        frame = new JFrame();
        frame.setSize(300, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JMenuBar menuBar = new JMenuBar();
        menu = new JMenu("Menu");
        JMenuItem menuItem = testItem.getMenuItem();
        testItem.setProperties(menuItem);
        menu.add(menuItem);
        menuBar.add(menu);

        frame.setJMenuBar(menuBar);
        frame.setVisible(true);
    }
 
Example 3
Project: openjdk-jdk10   File: bug6921687.java   View Source Code Vote up 6 votes
private static void setup(JFrame frame) {
    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);

    // First Menu, F - Mnemonic
    JMenu firstMenu = new JMenu("First Menu");
    firstMenu.setMnemonic(KeyEvent.VK_F);
    firstMenu.add(new JMenuItem("One", KeyEvent.VK_O));
    firstMenu.add(new JMenuItem("Two", KeyEvent.VK_T));
    menuBar.add(firstMenu);

    // Second Menu, S - Mnemonic
    JMenu secondMenu = new JMenu("Second Menu");
    secondMenu.setMnemonic(KeyEvent.VK_S);
    secondMenu.add(new JMenuItem("A Menu Item", KeyEvent.VK_A));
    menuBar.add(secondMenu);

    frame.setSize(350, 250);
    frame.setVisible(true);
}
 
Example 4
Project: ElectroLight-Penetration-Testing   File: Gui.java   View Source Code Vote up 6 votes
public Gui() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
	UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
	frame = new JFrame("ElectroLight Penetration Testing");
	menuBar = new JMenuBar();
	frame.setJMenuBar(menuBar);
	
	JMenu mnCounterhack = new JMenu("Counter-hack");
	menuBar.add(mnCounterhack);
	
	JMenuItem mntmArpScan = new JMenuItem("ARP Scan");
	mnCounterhack.add(mntmArpScan);
	frame.setSize(300, 200);
	
	JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
	frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
	
	// Always keep the 2 following lines at the end.
	//frame.pack();
	frame.setVisible(true);
}
 
Example 5
Project: jdk8u-jdk   File: ScreenMenuMemoryLeakTest.java   View Source Code Vote up 6 votes
private static void showUI() {
    sFrame = new JFrame();
    sFrame.add(new JLabel("Some dummy content"));

    JMenuBar menuBar = new JMenuBar();

    sMenu = new JMenu("Menu");
    JMenuItem item = new JMenuItem("Item");
    sMenu.add(item);

    sMenuItem = new WeakReference<>(item);

    menuBar.add(sMenu);

    sFrame.setJMenuBar(menuBar);

    sFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    sFrame.pack();
    sFrame.setVisible(true);
}
 
Example 6
Project: jdk8u-jdk   File: bug8071705.java   View Source Code Vote up 6 votes
private static JFrame createGUI() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Some menu");
    menuBar.add(menu);

    for (int i = 0; i < 10; i++) {
        menu.add(new JMenuItem("Some menu #" + i));
    }

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setMinimumSize(new Dimension(200, 200));
    frame.setJMenuBar(menuBar);
    return frame;
}
 
Example 7
Project: TuLiPA-frames   File: InputGUI.java   View Source Code Vote up 5 votes
public InputGUI(CommandLineOptions ops) {
    Thread splash = new Thread(new SplashScreen());
    splash.start();

    System.setErr(errs);
    pt = new Thread();

    guiFrame = new JFrame();
    guiFrame.setTitle("TuLiPA " + InputGUI.VERSION);
    guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    guiFrame.setJMenuBar(getMenuBar());
    guiFrame.setContentPane(getContainer());
    guiFrame.pack();
    guiFrame.setResizable(false);
    guiFrame.setLocationRelativeTo(null);

    shellFrame = new JFrame();
    shellFrame.setTitle("TuLiPA shell");
    shellFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    shellFrame.setContentPane(auxshell);
    shellFrame.setSize(new Dimension(400, 300));
    shellFrame.setResizable(true);
    shellFrame.setLocationRelativeTo(guiFrame);

    this.setOps(ops);
    localops = null;

    guiFrame.setVisible(true);

}
 
Example 8
Project: marathonv5   File: MenuDemo.java   View Source Code Vote up 5 votes
/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 */
private static void createAndShowGUI() {
    // Create and set up the window.
    JFrame frame = new JFrame("MenuDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

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

    // Display the window.
    frame.setSize(450, 260);
    frame.setVisible(true);
}
 
Example 9
Project: marathonv5   File: MenuSelectionManagerDemo.java   View Source Code Vote up 5 votes
/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 */
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);
}
 
Example 10
Project: openjdk-jdk10   File: bug8071705.java   View Source Code Vote up 5 votes
private static JFrame createGUI() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Some menu");
    menuBar.add(menu);

    for (int i = 0; i < 10; i++) {
        menu.add(new JMenuItem("Some menu #" + i));
    }

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setMinimumSize(new Dimension(200, 200));
    frame.setJMenuBar(menuBar);
    return frame;
}
 
Example 11
Project: marathonv5   File: MenuLookDemo.java   View Source Code Vote up 5 votes
/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 */
private static void createAndShowGUI() {
    // Create and set up the window.
    JFrame frame = new JFrame("MenuLookDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

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

    // Display the window.
    frame.setSize(450, 260);
    frame.setVisible(true);
}
 
Example 12
Project: VASSAL-src   File: ChatServerControls.java   View Source Code Vote up 5 votes
public void toggleVisible() {
  if (controlPanel.getTopLevelAncestor() == null) {
    if (GlobalOptions.getInstance().isUseSingleWindow()) {
      splitter = new ComponentSplitter().splitRight(GameModule.getGameModule().getControlPanel(), controlPanel, false);
      splitter.revalidate();
      final Runnable runnable = new Runnable() {
        public void run() {
          splitter.showComponent();
        }
      };
      SwingUtilities.invokeLater(runnable);
    }
    else {
      final JFrame frame = new JFrame(Resources.getString("Chat.server"));  //$NON-NLS-1$
      frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
      frame.add(controlPanel);
      frame.setJMenuBar(MenuManager.getInstance().getMenuBarFor(frame));

      final String key = "BoundsOfClientWindow";  //$NON-NLS-1$
      final PositionOption pos = new VisibilityOption(key, frame);
      GameModule.getGameModule().getPrefs().addOption(pos);
      frame.setVisible(true);
    }
  }
  else if (splitter != null) {
    splitter.toggleVisibility();
  }
  else {
    controlPanel.getTopLevelAncestor().setVisible(!controlPanel.getTopLevelAncestor().isVisible());
  }
}
 
Example 13
Project: formatter   File: FormatMain.java   View Source Code Vote up 5 votes
/**
* 
* @Title: init 
* @Description: Component Initialization 
* @param
* @return void 
* @throws
 */
private static void init()
{
    MenuBarView mbv = new MenuBarView();
    JFrame frame = new JFrame(FormatConst.FORMAT_VERSION);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(mbv.getJMenuBar());
    frame.getContentPane().add(FormatView.getView());
    frame.pack();
    frame.setVisible(true);
    frame.setIconImage(FormatUtil.getImage(FormatConst.LOGO));
    FormatUtil.setLocation(frame);
}
 
Example 14
Project: openjdk-jdk10   File: MisplacedBorder.java   View Source Code Vote up 5 votes
@Override
public void run() {
    final JMenuBar menubar = new JMenuBar();
    menubar.add(new JMenu(""));
    menubar.add(new JMenu(""));
    final JFrame frame = new JFrame();
    frame.setUndecorated(true);
    frame.setJMenuBar(menubar);
    frame.setSize(W / 3, H / 3);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    // draw menu bar using standard order.
    final BufferedImage bi1 = step1(menubar);

    // draw menu border on top of the menu bar, nothing should be changed.
    final BufferedImage bi2 = step2(menubar);
    frame.dispose();

    for (int x = 0; x < W; ++x) {
        for (int y = 0; y < H; ++y) {
            if (bi1.getRGB(x, y) != bi2.getRGB(x, y)) {
                try {
                    ImageIO.write(bi1, "png", new File("image1.png"));
                    ImageIO.write(bi2, "png", new File("image2.png"));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                throw new RuntimeException("Failed: wrong color");
            }
        }
    }
}
 
Example 15
Project: class-code   File: GeometricTreeDemo.java   View Source Code Vote up 5 votes
/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 */
private static void createAndShowGUI() {
	// Create and set up the window.
	JFrame frame = new JFrame("MenuDemo");
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

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

	// Display the window.
	frame.setSize(450, 260);
	frame.setVisible(true);
}
 
Example 16
Project: Tarski   File: BasicGraphEditor.java   View Source Code Vote up 5 votes
/**
 * 
 */
public JFrame createFrame(JMenuBar menuBar)
{
	JFrame frame = new JFrame();
	frame.getContentPane().add(this);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setJMenuBar(menuBar);
	frame.setSize(870, 640);

	// Updates the frame title
	updateTitle();

	return frame;
}
 
Example 17
Project: Tarski   File: BasicGraphEditor.java   View Source Code Vote up 5 votes
/**
 * 
 */
public JFrame createFrame(JMenuBar menuBar) {
  JFrame frame = new JFrame();
  frame.getContentPane().add(this);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setJMenuBar(menuBar);
  frame.setSize(870, 640);

  // Updates the frame title
  updateTitle();

  return frame;
}
 
Example 18
Project: jdk8u-jdk   File: MisplacedBorder.java   View Source Code Vote up 5 votes
@Override
public void run() {
    final JMenuBar menubar = new JMenuBar();
    menubar.add(new JMenu(""));
    menubar.add(new JMenu(""));
    final JFrame frame = new JFrame();
    frame.setUndecorated(true);
    frame.setJMenuBar(menubar);
    frame.setSize(W / 3, H / 3);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    // draw menu bar using standard order.
    final BufferedImage bi1 = step1(menubar);

    // draw menu border on top of the menu bar, nothing should be changed.
    final BufferedImage bi2 = step2(menubar);
    frame.dispose();

    for (int x = 0; x < W; ++x) {
        for (int y = 0; y < H; ++y) {
            if (bi1.getRGB(x, y) != bi2.getRGB(x, y)) {
                try {
                    ImageIO.write(bi1, "png", new File("image1.png"));
                    ImageIO.write(bi2, "png", new File("image2.png"));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                throw new RuntimeException("Failed: wrong color");
            }
        }
    }
}
 
Example 19
Project: openjdk-jdk10   File: bug4213634.java   View Source Code Vote up 5 votes
public  void createAndShowGUI() {
    frame = new JFrame("TEST");
    JMenuBar mb = new JMenuBar();
    menu = mb.add(createMenu("1 - First Menu", true));
    mb.add(createMenu("2 - Second Menu", false));
    frame.setJMenuBar(mb);
    JTextArea ta = new JTextArea("This test dedicated to Nancy and Kathleen, testers and bowlers extraordinaire\n\n\nNo exception means pass.");
    frame.getContentPane().add("Center", ta);
    JButton button = new JButton("Test");
    frame.getContentPane().add("South", button);
    frame.setBounds(100, 100, 400, 400);
    frame.setVisible(true);
    button.requestFocusInWindow();
}
 
Example 20
Project: openjdk-jdk10   File: ClickMenuTestManual.java   View Source Code Vote up 4 votes
public final void createControlPanelUI() throws Exception {
    layout = new GridBagLayout();
    mainControlPanel = new JPanel(layout);
    instructionPanel = new JPanel(layout);
    testPanel = new JPanel(layout);
    resultButtonPanel = new JPanel(layout);
    controlPanel = new JPanel(layout);

    GridBagConstraints gbc = new GridBagConstraints();
    String instructions
            = "1) Click on MENU using mouse "
            + "\n2) Click on MENU ITEM using mouse "
            + "\n3) Check output on textArea if equal to STRING "
            + "\n\n If correct string, press \"Pass\" "
            + "\n Otherwise, press \"Fail\" ";
    instructionTextArea = new JTextArea();
    instructionTextArea.setText(instructions);
    instructionTextArea.setEnabled(false);
    instructionTextArea.setDisabledTextColor(Color.black);
    instructionTextArea.setBackground(Color.white);
    instructionTextArea.setBorder(
            BorderFactory.createLineBorder(Color.black));
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    instructionPanel.add(instructionTextArea, gbc);
    testTextArea = new JTextArea();
    testTextArea.setEnabled(true);
    testTextArea.setDisabledTextColor(Color.black);
    testTextArea.setBackground(Color.white);
    testTextArea.setBorder(
            BorderFactory.createLineBorder(Color.black));
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    testPanel.add(testTextArea, gbc);
    passButton = new JButton("Pass");
    passButton.setActionCommand("Pass");
    passButton.addActionListener(this);
    failButton = new JButton("Fail");
    failButton.setActionCommand("Fail");
    failButton.addActionListener(this);
    gbc.gridx = 0;
    gbc.gridy = 0;
    resultButtonPanel.add(passButton, gbc);
    gbc.gridx = 1;
    gbc.gridy = 0;
    resultButtonPanel.add(failButton, gbc);
    gbc.gridx = 0;
    gbc.gridy = 0;
    mainControlPanel.add(instructionPanel, gbc);
    gbc.gridx = 0;
    gbc.gridy = 1;
    mainControlPanel.add(testPanel, gbc);
    gbc.gridx = 0;
    gbc.gridy = 2;
    mainControlPanel.add(resultButtonPanel, gbc);
    gbc.gridx = 0;
    gbc.gridy = 3;
    mainControlPanel.add(controlPanel, gbc);
    mainFrame = new JFrame("Control Panel");
    mainFrame.add(mainControlPanel);
    menuBar = new JMenuBar();
    menu = new JMenu("MENU");
    menuItem = new JMenuItem("MENU ITEM");
    menuItem.addActionListener((e) -> {
        testTextArea.setText(TEST_STRING);
    });
    menu.add(menuItem);
    menuBar.add(menu);
    mainFrame.setJMenuBar(menuBar);
    mainFrame.pack();
    mainFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    mainFrame.setVisible(true);

}