List of usage examples for javax.swing JMenuBar JMenuBar
public JMenuBar()
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); ComponentOrientation ori = ComponentOrientation.LEFT_TO_RIGHT; menu.applyComponentOrientation(ori); bar.add(menu);/*from w w w.j ava 2 s. c om*/ menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR JMenuItem item = new JMenuItem("Exit"); menu.add(item); setJMenuBar(bar); add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); menu.removeAll(); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); ComponentOrientation ori = ComponentOrientation.LEFT_TO_RIGHT; menu.applyComponentOrientation(ori); bar.add(menu);//from w ww . jav a2 s. c om menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR JMenuItem item = new JMenuItem("Exit"); menu.add(item); setJMenuBar(bar); add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); menu.remove(item); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); ComponentOrientation ori = ComponentOrientation.LEFT_TO_RIGHT; menu.applyComponentOrientation(ori); bar.add(menu);// w w w .j a v a 2 s . c o m menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR menu.add(new AbstractAction("Exit") { @Override public void actionPerformed(ActionEvent arg0) { System.out.println("action"); } }); setJMenuBar(bar); add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); ComponentOrientation ori = ComponentOrientation.LEFT_TO_RIGHT; menu.applyComponentOrientation(ori); bar.add(menu);//from w w w .j a v a 2 s .c o m menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR menu.add(new JMenuItem("Exit")); setJMenuBar(bar); add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); menu.insert(new AbstractAction("Action") { @Override public void actionPerformed(ActionEvent arg0) { } }, 0); }
From source file:Main.java
Main() { JFrame f = new JFrame("Menu Demo"); f.setSize(220, 200);//from w w w.j a va 2 s . com f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar jmb = new JMenuBar(); JMenu jmFile = new JMenu("File"); JMenuItem jmiOpen = new JMenuItem("Open"); JMenuItem jmiClose = new JMenuItem("Close"); JMenuItem jmiSave = new JMenuItem("Save"); JMenuItem jmiExit = new JMenuItem("Exit"); jmFile.add(jmiOpen); jmFile.add(jmiClose); jmFile.add(jmiSave); jmFile.addSeparator(); jmFile.add(jmiExit); jmb.add(jmFile); JMenu jmOptions = new JMenu("Options"); JMenu a = new JMenu("A"); JMenuItem b = new JMenuItem("B"); JMenuItem c = new JMenuItem("C"); JMenuItem d = new JMenuItem("D"); a.add(b); a.add(c); a.add(d); jmOptions.add(a); JMenu e = new JMenu("E"); e.add(new JMenuItem("F")); e.add(new JMenuItem("G")); jmOptions.add(e); jmb.add(jmOptions); JMenu jmHelp = new JMenu("Help"); JMenuItem jmiAbout = new JMenuItem("About"); jmHelp.add(jmiAbout); jmb.add(jmHelp); jmiOpen.addActionListener(this); jmiClose.addActionListener(this); jmiSave.addActionListener(this); jmiExit.addActionListener(this); b.addActionListener(this); c.addActionListener(this); d.addActionListener(this); jmiAbout.addActionListener(this); f.setJMenuBar(jmb); f.setVisible(true); }
From source file:Main.java
public Main() { JMenuBar bar = new JMenuBar(); JMenu addMenu = new JMenu("Add"); JMenuItem newFrame = new JMenuItem("Internal Frame"); addMenu.add(newFrame);/*from ww w. j av a 2s . c o m*/ bar.add(addMenu); setJMenuBar(bar); final JDesktopPane theDesktop = new JDesktopPane(); getContentPane().add(theDesktop); newFrame.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JInternalFrame frame = new JInternalFrame("Internal Frame", true, true, true, true); Container c = frame.getContentPane(); MyJPanel panel = new MyJPanel(); c.add(panel, BorderLayout.CENTER); frame.setSize(200, 200); frame.setOpaque(true); theDesktop.add(frame); } }); setSize(500, 400); setVisible(true); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("Checkable"); bar.add(menu);//from w w w. java 2s .com menu.add(check); check.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { System.out.println("Checked? " + check.isSelected()); } }); setJMenuBar(bar); getContentPane().add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); }
From source file:Main.java
public Main() { setTitle("ZipTest"); setSize(300, 400);// w w w . j a v a2 s. c o m JMenuBar mbar = new JMenuBar(); JMenu m = new JMenu("File"); openItem = new JMenuItem("Open"); openItem.addActionListener(this); m.add(openItem); exitItem = new JMenuItem("Exit"); exitItem.addActionListener(this); m.add(exitItem); mbar.add(m); Container contentPane = getContentPane(); contentPane.add(mbar, "North"); }
From source file:ImageViewer.java
public ImageViewer() { setTitle("ImageViewer"); setSize(300, 400);/* www .j a va 2 s . c om*/ JMenuBar mbar = new JMenuBar(); JMenu m = new JMenu("File"); openItem = new JMenuItem("Open"); openItem.addActionListener(this); m.add(openItem); exitItem = new JMenuItem("Exit"); exitItem.addActionListener(this); m.add(exitItem); mbar.add(m); setJMenuBar(mbar); label = new JLabel(); Container contentPane = getContentPane(); contentPane.add(label, "Center"); }
From source file:FileChooserDemo.java
public FileChooserDemo() { setTitle("ZipTest"); setSize(300, 400);/*from w ww . j a va2 s .c o m*/ JMenuBar mbar = new JMenuBar(); JMenu m = new JMenu("File"); openItem = new JMenuItem("Open"); openItem.addActionListener(this); m.add(openItem); exitItem = new JMenuItem("Exit"); exitItem.addActionListener(this); m.add(exitItem); mbar.add(m); Container contentPane = getContentPane(); contentPane.add(mbar, "North"); }