List of usage examples for javax.swing JMenuItem JMenuItem
public JMenuItem(Action a)
Action
. From source file:Main.java
public static void main(String[] argv) throws Exception { JMenuItem item = new JMenuItem("Label") { public void menuSelectionChanged(boolean isSelected) { super.menuSelectionChanged(isSelected); if (isSelected) { System.out.println("The menu item is selected"); } else { System.out.println("The menu item is no longer selected"); }/* w w w .j a v a2 s.co m*/ } }; }
From source file:Main.java
public static void main(String[] argv) throws Exception { JMenuItem item = new JMenuItem("Item"); item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, KeyEvent.SHIFT_MASK)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JMenu menu = new JMenu("Menu Label"); menu.add(new JMenuItem("Item Label")); boolean lwPopup = menu.getPopupMenu().isLightWeightPopupEnabled(); // true menu.getPopupMenu().setLightWeightPopupEnabled(false); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JMenu menu = new JMenu("Menu Label"); JMenuItem item1 = new JMenuItem("Item Label"); menu.add(item1);/*from w ww. j a v a2 s . c o m*/ // Add separator menu.add(new JSeparator()); // Add another menu item JMenuItem item2 = new JMenuItem("Item Label"); menu.add(item2); }
From source file:Main.java
public static void main(String[] argv) throws Exception { final JPopupMenu menu = new JPopupMenu(); JMenuItem item = new JMenuItem("Item Label"); menu.add(item);/*from ww w . ja va 2 s . c om*/ JButton component = new JButton("button"); component.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent evt) { if (evt.isPopupTrigger()) { menu.show(evt.getComponent(), evt.getX(), evt.getY()); } } public void mouseReleased(MouseEvent evt) { if (evt.isPopupTrigger()) { menu.show(evt.getComponent(), evt.getX(), evt.getY()); } } }); }
From source file:Main.java
public static void main(String[] argv) throws Exception { final JPopupMenu menu = new JPopupMenu(); JMenuItem item = new JMenuItem("Item Label"); // item.addActionListener(actionListener); menu.add(item);//w ww.ja va 2s. c o m JButton component = new JButton("button"); component.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent evt) { if (evt.isPopupTrigger()) { menu.show(evt.getComponent(), evt.getX(), evt.getY()); } } public void mouseReleased(MouseEvent evt) { if (evt.isPopupTrigger()) { menu.show(evt.getComponent(), evt.getX(), evt.getY()); } } }); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPopupMenu popupMenu = new JPopupMenu(); popupMenu.add(new JMenuItem("One")); popupMenu.add(new JMenuItem("Two")); popupMenu.add(new JMenuItem("Three")); JList<String> list = new JList<>( new String[] { "Hello", "World", "Something", "Else", "Out", "Of", "Ideas" }); list.setComponentPopupMenu(popupMenu); f.add(list);/* w ww.ja va2 s. c o m*/ f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { // Create the menu bar JMenuBar menuBar = new JMenuBar(); // Create a menu JMenu menu = new JMenu("Menu Label"); menuBar.add(menu);// w w w . j a v a 2 s. co m // Create a menu item JMenuItem item = new JMenuItem("Item Label"); //item.addActionListener(actionListener); menu.add(item); JFrame frame = new JFrame(); // Install the menu bar in the frame frame.setJMenuBar(menuBar); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); // File Menu, F - Mnemonic JMenu fileMenu = new JMenu("File"); // File->New, N - Mnemonic JMenuItem newMenuItem = new JMenuItem("New"); fileMenu.add(newMenuItem);//from w w w . j a v a 2 s . com frame.setJMenuBar(menuBar); frame.setSize(350, 250); frame.setVisible(true); fileMenu.setSelected(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); // File Menu, F - Mnemonic JMenu fileMenu = new JMenu("File"); // File->New, N - Mnemonic JMenuItem newMenuItem = new JMenuItem("New"); fileMenu.add(newMenuItem);/*from w ww.ja v a 2s . com*/ frame.setJMenuBar(menuBar); frame.setSize(350, 250); frame.setVisible(true); fileMenu.setPopupMenuVisible(true); }