Java Code Examples for javax.swing.JFrame#setJMenuBar()
The following examples show how to use
javax.swing.JFrame#setJMenuBar() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: TencentKona-8 File: ScreenMenuMemoryLeakTest.java License: GNU General Public License v2.0 | 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 2
Source Project: TencentKona-8 File: bug8071705.java License: GNU General Public License v2.0 | 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 3
Source Project: jdk8u-jdk File: ScreenMenuMemoryLeakTest.java License: GNU General Public License v2.0 | 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 4
Source Project: openjdk-jdk9 File: SilenceOfDeprecatedMenuBar.java License: GNU General Public License v2.0 | 6 votes |
@Override public void run() { final JFrame frame = new DeprecatedFrame(); try { final JMenuBar bar = new JMenuBar(); frame.setJMenuBar(bar); frame.setBounds(100, 100, 100, 100); frame.setLocationRelativeTo(null); frame.setVisible(true); if (bar != frame.getJMenuBar()) { throw new RuntimeException("Wrong JMenuBar"); } } finally { frame.dispose(); } }
Example 5
Source Project: marathonv5 File: PopupMenuDemoX.java License: Apache License 2.0 | 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 6
Source Project: blog-codes File: BasicGraphEditor.java License: Apache License 2.0 | 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 7
Source Project: MeteoInfo File: FrmCustom.java License: GNU Lesser General Public License v3.0 | 5 votes |
private void init_Figure() { JFrame window = getFrame(); JMenuBar menuBar = new JMenuBar(); menuBar.add(new JMenu("File")); menuBar.add(new JMenu("Figure")); window.setJMenuBar(menuBar); JToolBar toolBar = new JToolBar(); JButton jButton_ZoomIn = new JButton(); jButton_ZoomIn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/TSB_ZoomIn.Image.png"))); // NOI18N jButton_ZoomIn.setToolTipText("Zoom In"); // NOI18N jButton_ZoomIn.setFocusable(false); jButton_ZoomIn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton_ZoomIn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jButton_ZoomIn.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { //jButton_ZoomInActionPerformed(evt); } }); toolBar.add(jButton_ZoomIn); JButton jButton_ZoomOut = new JButton(); JButton jButton_Pan = new JButton(); JButton jButton_FullExtent = new JButton(); //window.getContentPane().setLayout(new GridLayout(2, 1)); //window.add(toolBar); window.getContentPane().add(toolBar, BorderLayout.PAGE_START); }
Example 8
Source Project: jdk8u_jdk File: bug8071705.java License: GNU General Public License v2.0 | 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 9
Source Project: jdk8u_jdk File: MisplacedBorder.java License: GNU General Public License v2.0 | 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 10
Source Project: openjdk-jdk8u-backup File: bug8071705.java License: GNU General Public License v2.0 | 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
Source Project: openjdk-jdk9 File: JMenuBarOverlapping.java License: GNU General Public License v2.0 | 5 votes |
protected void prepareControls() { frame = new JFrame("Mixing : Dropdown Overlapping test"); frame.setLayout(new GridLayout(0,1)); frame.setSize(200, 200); frame.setVisible(true); menuBar = new JMenuBar(); JMenu menu = new JMenu("Test Menu"); ActionListener menuListener = new ActionListener() { public void actionPerformed(ActionEvent event) { lwClicked = true; } }; JMenuItem item; menu.add(item = new JMenuItem("first")); item.addActionListener(menuListener); separator = new JSeparator(); separator.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { spClicked = true; } }); menu.add(separator); for (int i = 0; i < petStrings.length; i++) { menu.add(item = new JMenuItem(petStrings[i])); item.addActionListener(menuListener); } menuBar.add(menu); frame.setJMenuBar(menuBar); propagateAWTControls(frame); frame.setVisible(true); }
Example 12
Source Project: TencentKona-8 File: MisplacedBorder.java License: GNU General Public License v2.0 | 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 13
Source Project: rest-client File: RESTMain.java License: Apache License 2.0 | 5 votes |
/** * * @Title: init * @Description: Component Initialization * @param * @return void * @throws */ public static void init() { MenuBarView mbv = new MenuBarView(); JFrame frame = new JFrame(RESTConst.REST_CLIENT_VERSION); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setJMenuBar(mbv.getJMenuBar()); frame.getContentPane().add(RESTView.getView()); frame.pack(); frame.setVisible(true); frame.addWindowListener(wa); frame.setIconImage(UIUtil.getImage(RESTConst.LOGO)); frame.setMinimumSize(new Dimension(RESTConst.MAIN_FRAME_WIDTH, RESTConst.MAIN_FRAME_HEIGHT)); UIUtil.setLocation(frame); }
Example 14
Source Project: jdk8u60 File: bug8071705.java License: GNU General Public License v2.0 | 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 15
Source Project: hottub File: MisplacedBorder.java License: GNU General Public License v2.0 | 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 16
Source Project: openjdk-jdk8u File: bug8071705.java License: GNU General Public License v2.0 | 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 17
Source Project: hottub File: bug8071705.java License: GNU General Public License v2.0 | 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 18
Source Project: openjdk-jdk9 File: MisplacedBorder.java License: GNU General Public License v2.0 | 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
Source Project: openjdk-jdk9 File: ClickMenuTestManual.java License: GNU General Public License v2.0 | 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); }
Example 20
Source Project: nmonvisualizer File: NMONVisualizerGui.java License: Apache License 2.0 | 4 votes |
public NMONVisualizerGui() throws Exception { super(); granularityHelper = new GranularityHelper(this); setGranularity(-1); // automatic reportCache = new ReportCache(); chartFormatter = new ChartFormatter(); preferences = Preferences.userNodeForPackage(NMONVisualizerGui.class); setProperty("chartsDisplayed", true); setProperty("lineChartLegend", preferences.getBoolean("lineChartLegend", true)); String systemsNamedBy = preferences.get("systemsNamedBy", null); if (systemsNamedBy != null) { if ("host".equals(systemsNamedBy)) { setHostRenamer(HostRenamer.BY_HOST); } else if ("lpar".equals(systemsNamedBy)) { setHostRenamer(HostRenamer.BY_LPAR); } else if ("run".equals(systemsNamedBy)) { setHostRenamer(HostRenamer.BY_RUN); } else if ("custom".equals(systemsNamedBy)) { // reset back to host if custom since the JSON file to load is not known systemsNamedBy = "host"; } setProperty("systemsNamedBy", systemsNamedBy); } // else NMONVisualizerApp already set HostRenamer to BY_HOST and systemsNamedBy property // NMONVisuzlizerApp already set default value for scaleProcessesByCPUs property setProperty("scaleProcessesByCPUs", preferences.get("scaleProcessesByCPUs", getProperty("scaleProcessesByCPUs"))); setProperty("showStatusBar", preferences.get("showStatusBar", "false")); mainFrame = new JFrame(DEFAULT_WINDOW_TITLE); mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); mainFrame.addWindowListener(windowManager); mainFrame.setIconImage(Styles.IBM_ICON.getImage()); menu = new MainMenu(this); mainFrame.setJMenuBar(menu); logViewer = new LogViewerDialog(this); // tree of parsed files on the left, content on the left JSplitPane lrSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); // never resize tree automatically lrSplitPane.setResizeWeight(0); mainFrame.setContentPane(lrSplitPane); // tree of parsed files on the left, content on the right TreePanel treePanel = new TreePanel(this); JPanel right = new JPanel(new BorderLayout()); lrSplitPane.setLeftComponent(treePanel); lrSplitPane.setRightComponent(right); ChartTableToggle toggle = new ChartTableToggle(this); JPanel top = new JPanel(new BorderLayout()); top.add(new IntervalPicker(this), BorderLayout.CENTER); top.add(toggle, BorderLayout.LINE_END); right.add(top, BorderLayout.PAGE_START); // ViewManager's SummaryView adds the checkbox to the top panel // so top must already be created and added to the gui before the data panel is initialized ViewManager dataPanel = new ViewManager(this); StatusBar statusBar = new StatusBar(this); treePanel.addTreeSelectionListener(dataPanel); treePanel.addTreeSelectionListener(statusBar); right.add(dataPanel, BorderLayout.CENTER); right.add(statusBar, BorderLayout.PAGE_END); mainFrame.pack(); positionMainFrame(); }