List of usage examples for javax.swing JMenuItem setEnabled
@BeanProperty(preferred = true, description = "The enabled state of the component.") public void setEnabled(boolean b)
From source file:PopupSample.java
public static void main(final String args[]) { JFrame frame = new JFrame("PopupSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create popup menu, attach popup menu listener JPopupMenu popupMenu = new JPopupMenu("Title"); // Cut//ww w. j ava 2s.c om JMenuItem cutMenuItem = new JMenuItem("Cut"); popupMenu.add(cutMenuItem); // Copy JMenuItem copyMenuItem = new JMenuItem("Copy"); popupMenu.add(copyMenuItem); // Paste JMenuItem pasteMenuItem = new JMenuItem("Paste"); pasteMenuItem.setEnabled(false); popupMenu.add(pasteMenuItem); // Separator popupMenu.addSeparator(); // Find JMenuItem findMenuItem = new JMenuItem("Find"); popupMenu.add(findMenuItem); JButton label = new JButton(); frame.add(label); label.setComponentPopupMenu(popupMenu); frame.setSize(350, 250); frame.setVisible(true); }
From source file:MyPopupMenuListener.java
public static void main(final String args[]) { JFrame frame = new JFrame("Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPopupMenu popupMenu = new JPopupMenu("Title"); PopupMenuListener popupMenuListener = new MyPopupMenuListener(); popupMenu.addPopupMenuListener(popupMenuListener); JMenuItem cutMenuItem = new JMenuItem("Cut"); popupMenu.add(cutMenuItem);// w w w.j a v a 2 s. c o m JMenuItem copyMenuItem = new JMenuItem("Copy"); popupMenu.add(copyMenuItem); JMenuItem pasteMenuItem = new JMenuItem("Paste"); pasteMenuItem.setEnabled(false); popupMenu.add(pasteMenuItem); popupMenu.addSeparator(); JMenuItem findMenuItem = new JMenuItem("Find"); popupMenu.add(findMenuItem); JButton label = new JButton(); frame.add(label); label.setComponentPopupMenu(popupMenu); frame.setSize(350, 250); frame.setVisible(true); }
From source file:MyPopupMenuListener.java
public static void main(final String args[]) { JFrame frame = new JFrame("PopupSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create popup menu, attach popup menu listener JPopupMenu popupMenu = new JPopupMenu("Title"); PopupMenuListener popupMenuListener = new MyPopupMenuListener(); popupMenu.addPopupMenuListener(popupMenuListener); // Cut//from w ww. j av a2 s. co m JMenuItem cutMenuItem = new JMenuItem("Cut"); popupMenu.add(cutMenuItem); // Copy JMenuItem copyMenuItem = new JMenuItem("Copy"); popupMenu.add(copyMenuItem); // Paste JMenuItem pasteMenuItem = new JMenuItem("Paste"); pasteMenuItem.setEnabled(false); popupMenu.add(pasteMenuItem); // Separator popupMenu.addSeparator(); // Find JMenuItem findMenuItem = new JMenuItem("Find"); popupMenu.add(findMenuItem); JButton label = new JButton(); frame.add(label); label.setComponentPopupMenu(popupMenu); frame.setSize(350, 250); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("MenuSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); // File Menu, F - Mnemonic JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu);// w ww .j a v a 2s .c om // File->New, N - Mnemonic JMenuItem newMenuItem = new JMenuItem("New", KeyEvent.VK_N); newMenuItem.setEnabled(false); fileMenu.add(newMenuItem); JCheckBoxMenuItem caseMenuItem = new JCheckBoxMenuItem("Case Sensitive"); caseMenuItem.setMnemonic(KeyEvent.VK_C); fileMenu.add(caseMenuItem); ActionListener aListener = new ActionListener() { public void actionPerformed(ActionEvent event) { AbstractButton aButton = (AbstractButton) event.getSource(); boolean selected = aButton.getModel().isSelected(); String newLabel; if (selected) { newLabel = "A"; } else { newLabel = "B"; } aButton.setText(newLabel); } }; caseMenuItem.addActionListener(aListener); frame.setJMenuBar(menuBar); frame.setSize(350, 250); frame.setVisible(true); }
From source file:PopupActionListener.java
public static void main(final String args[]) { JFrame frame = new JFrame("PopupSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create popup menu, attach popup menu listener JPopupMenu popupMenu = new JPopupMenu("Title"); ActionListener actionListener = new PopupActionListener(); // Cut/*from w w w. j a va2 s . com*/ JMenuItem cutMenuItem = new JMenuItem("Cut"); popupMenu.add(cutMenuItem); // Copy JMenuItem copyMenuItem = new JMenuItem("Copy"); copyMenuItem.addActionListener(actionListener); popupMenu.add(copyMenuItem); // Paste JMenuItem pasteMenuItem = new JMenuItem("Paste"); pasteMenuItem.addActionListener(actionListener); pasteMenuItem.setEnabled(false); popupMenu.add(pasteMenuItem); // Separator popupMenu.addSeparator(); // Find JMenuItem findMenuItem = new JMenuItem("Find"); findMenuItem.addActionListener(actionListener); popupMenu.add(findMenuItem); JButton label = new JButton(); frame.add(label); label.setComponentPopupMenu(popupMenu); frame.setSize(350, 250); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ActionListener actionListener = new PopupActionListener(); PopupMenuListener popupMenuListener = new MyPopupMenuListener(); JPopupMenu popupMenu = new JPopupMenu("Title"); popupMenu.addPopupMenuListener(popupMenuListener); JMenuItem cutMenuItem = new JMenuItem("Cut"); cutMenuItem.addActionListener(actionListener); popupMenu.add(cutMenuItem);/* w w w . j a v a 2 s. co m*/ JMenuItem copyMenuItem = new JMenuItem("Copy"); copyMenuItem.addActionListener(actionListener); popupMenu.add(copyMenuItem); JMenuItem pasteMenuItem = new JMenuItem("Paste"); pasteMenuItem.addActionListener(actionListener); pasteMenuItem.setEnabled(false); popupMenu.add(pasteMenuItem); popupMenu.addSeparator(); JMenuItem findMenuItem = new JMenuItem("Find"); findMenuItem.addActionListener(actionListener); popupMenu.add(findMenuItem); JButton label = new JButton(); frame.add(label); label.setComponentPopupMenu(popupMenu); frame.setSize(350, 250); frame.setVisible(true); }
From source file:PopupSample.java
public static void main(String args[]) { ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Selected: " + actionEvent.getActionCommand()); }/*from w w w. j a v a2s . c o m*/ }; PopupMenuListener popupMenuListener = new PopupMenuListener() { public void popupMenuCanceled(PopupMenuEvent popupMenuEvent) { System.out.println("Canceled"); } public void popupMenuWillBecomeInvisible(PopupMenuEvent popupMenuEvent) { System.out.println("Becoming Invisible"); } public void popupMenuWillBecomeVisible(PopupMenuEvent popupMenuEvent) { System.out.println("Becoming Visible"); } }; JFrame frame = new JFrame("Popup Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPopupMenu popupMenu = new JPopupMenu(); popupMenu.addPopupMenuListener(popupMenuListener); JMenuItem cutMenuItem = new JMenuItem("Cut"); cutMenuItem.addActionListener(actionListener); popupMenu.add(cutMenuItem); JMenuItem copyMenuItem = new JMenuItem("Copy"); copyMenuItem.addActionListener(actionListener); popupMenu.add(copyMenuItem); JMenuItem pasteMenuItem = new JMenuItem("Paste"); pasteMenuItem.addActionListener(actionListener); pasteMenuItem.setEnabled(false); popupMenu.add(pasteMenuItem); popupMenu.addSeparator(); JMenuItem findMenuItem = new JMenuItem("Find"); findMenuItem.addActionListener(actionListener); popupMenu.add(findMenuItem); MouseListener mouseListener = new JPopupMenuShower(popupMenu); frame.addMouseListener(mouseListener); frame.setSize(350, 250); frame.setVisible(true); }
From source file:JMenuItemDisabled.java
public static void main(final String args[]) { JFrame frame = new JFrame("MenuSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); // File Menu, F - Mnemonic JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu);/*from ww w . j a v a 2s. c o m*/ // File->New, N - Mnemonic JMenuItem newMenuItem = new JMenuItem("New", KeyEvent.VK_N); fileMenu.add(newMenuItem); // Edit->Paste, P - Mnemonic, CTRL-V - Accelerator, Disabled JMenuItem pasteMenuItem = new JMenuItem("Paste", KeyEvent.VK_P); KeyStroke ctrlVKeyStroke = KeyStroke.getKeyStroke("control V"); pasteMenuItem.setAccelerator(ctrlVKeyStroke); pasteMenuItem.setEnabled(false); fileMenu.add(pasteMenuItem); frame.setJMenuBar(menuBar); frame.setSize(350, 250); frame.setVisible(true); }
From source file:MediumPopupMenuSample.java
public static void main(String args[]) { // Define ActionListener ActionListener aListener = new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("Selected: " + event.getActionCommand()); }// w w w.j a va2 s . c o m }; // Define PopupMenuListener PopupMenuListener pListener = new PopupMenuListener() { public void popupMenuCanceled(PopupMenuEvent event) { System.out.println("Canceled"); } public void popupMenuWillBecomeInvisible(PopupMenuEvent event) { System.out.println("Becoming Invisible"); } public void popupMenuWillBecomeVisible(PopupMenuEvent event) { System.out.println("Becoming Visible"); } }; // Define JFrame frame = new JFrame("Popup Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPopupMenu.setDefaultLightWeightPopupEnabled(false); // Create popup menu, attach popup menu listener final JPopupMenu popupMenu = new JPopupMenu(); popupMenu.addPopupMenuListener(pListener); // Cut JMenuItem cutItem = new JMenuItem("Cut"); cutItem.addActionListener(aListener); popupMenu.add(cutItem); // Copy JMenuItem copyItem = new JMenuItem("Copy"); copyItem.addActionListener(aListener); popupMenu.add(copyItem); // Paste JMenuItem pasteItem = new JMenuItem("Paste"); pasteItem.addActionListener(aListener); pasteItem.setEnabled(false); popupMenu.add(pasteItem); // Separator popupMenu.addSeparator(); // Find JMenuItem findItem = new JMenuItem("Find"); findItem.addActionListener(aListener); popupMenu.add(findItem); // Enable showing MouseListener mouseListener = new JPopupMenuShower(popupMenu); frame.addMouseListener(mouseListener); Button button = new Button("Label"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(popupMenu.isLightWeightPopupEnabled()); } }); frame.getContentPane().add(button, BorderLayout.SOUTH); frame.setSize(350, 250); frame.setVisible(true); }
From source file:ToggleSample.java
public static void main(String args[]) { JFrame frame = new JFrame("JToggleButtonMenuItem Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu file = new JMenu("File"); file.setMnemonic('f'); JMenuItem newItem = new JMenuItem("New", 'N'); file.add(newItem);/* w w w . j a v a 2 s . com*/ JMenuItem openItem = new JMenuItem("Open", 'O'); file.add(openItem); JMenuItem closeItem = new JMenuItem("Close", 'C'); file.add(closeItem); file.addSeparator(); JMenuItem saveItem = new JMenuItem("Save", 'S'); file.add(saveItem); file.addSeparator(); JMenuItem exitItem = new JMenuItem("Exit", 'X'); file.add(exitItem); bar.add(file); JMenu edit = new JMenu("Edit"); JMenuItem cutItem = new JMenuItem("Cut", 'T'); cutItem.setAccelerator(KeyStroke.getKeyStroke('X', Event.CTRL_MASK)); edit.add(cutItem); JMenuItem copyItem = new JMenuItem("Copy", 'C'); copyItem.setAccelerator(KeyStroke.getKeyStroke('C', Event.CTRL_MASK)); edit.add(copyItem); JMenuItem pasteItem = new JMenuItem("Paste", 'P'); pasteItem.setAccelerator(KeyStroke.getKeyStroke('V', Event.CTRL_MASK)); pasteItem.setEnabled(false); edit.add(pasteItem); edit.addSeparator(); JMenuItem findItem = new JMenuItem("Find", 'F'); findItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0)); edit.add(findItem); edit.setMnemonic('e'); Icon atIcon = new ImageIcon("at.gif"); JMenu findOptions = new JMenu("Options"); findOptions.setIcon(atIcon); findOptions.setMnemonic('O'); ButtonGroup directionGroup = new ButtonGroup(); JRadioButtonMenuItem forward = new JRadioButtonMenuItem("Forward", true); findOptions.add(forward); directionGroup.add(forward); JRadioButtonMenuItem backward = new JRadioButtonMenuItem("Backward"); findOptions.add(backward); directionGroup.add(backward); findOptions.addSeparator(); JCheckBoxMenuItem caseItem = new JCheckBoxMenuItem("Case Insensitive"); findOptions.add(caseItem); edit.add(findOptions); JToggleButtonMenuItem toggleItem = new JToggleButtonMenuItem("Ballon Help"); toggleItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Selected"); } }); edit.add(toggleItem); bar.add(edit); frame.setJMenuBar(bar); frame.setSize(350, 250); frame.setVisible(true); }