List of usage examples for javax.swing JMenuItem addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:MessageDigestTest.java
public MessageDigestFrame() { setTitle("MessageDigestTest"); setSize(400, 200);//from w ww . ja v a 2 s . com addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); JPanel panel = new JPanel(); ButtonGroup group = new ButtonGroup(); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent event) { JCheckBox b = (JCheckBox) event.getSource(); setAlgorithm(b.getText()); } }; addCheckBox(panel, "SHA-1", group, true, listener); addCheckBox(panel, "MD5", group, false, listener); Container contentPane = getContentPane(); contentPane.add(panel, "North"); contentPane.add(new JScrollPane(message), "Center"); contentPane.add(digest, "South"); digest.setFont(new Font("Monospaced", Font.PLAIN, 12)); setAlgorithm("SHA-1"); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); JMenuItem fileDigestItem = new JMenuItem("File digest"); fileDigestItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { loadFile(); } }); menu.add(fileDigestItem); JMenuItem textDigestItem = new JMenuItem("Text area digest"); textDigestItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String m = message.getText(); computeDigest(m.getBytes()); } }); menu.add(textDigestItem); menuBar.add(menu); setJMenuBar(menuBar); }
From source file:Main.java
public Main(String title) { super(title); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); tabComponentsItem = new JCheckBoxMenuItem("Use TabComponents", true); tabComponentsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.ALT_MASK)); tabComponentsItem.addActionListener(e -> { for (int i = 0; i < pane.getTabCount(); i++) { if (tabComponentsItem.isSelected()) { } else { pane.setTabComponentAt(i, null); }//from w w w . jav a 2s.c o m } }); scrollLayoutItem = new JCheckBoxMenuItem("Set ScrollLayout"); scrollLayoutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.ALT_MASK)); scrollLayoutItem.addActionListener(e -> { if (pane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT) { pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); } else { pane.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT); } }); JMenuItem resetItem = new JMenuItem("Reset JTabbedPane"); resetItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.ALT_MASK)); resetItem.addActionListener(e -> runTest()); JMenu optionsMenu = new JMenu("Options"); optionsMenu.add(tabComponentsItem); optionsMenu.add(scrollLayoutItem); optionsMenu.add(resetItem); menuBar.add(optionsMenu); setJMenuBar(menuBar); add(pane); }
From source file:Main.java
public Main() { popup = new JPopupMenu(); ActionListener menuListener = new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("Popup menu item [" + event.getActionCommand() + "] was pressed."); }//w ww. j a va 2 s . c om }; JMenuItem item; popup.add(item = new JMenuItem(new ImageIcon("left.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Center", new ImageIcon("center.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Right", new ImageIcon("right.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Full", new ImageIcon("full.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.addSeparator(); popup.add(item = new JMenuItem("Settings . . .")); item.addActionListener(menuListener); popup.setLabel("Justification"); popup.setBorder(new BevelBorder(BevelBorder.RAISED)); popup.addPopupMenuListener(new PopupPrintListener()); addMouseListener(new MousePopupListener()); }
From source file:cz.lidinsky.editor.Menu.java
/** * Adds new menu item at the end of the menu. *//*from w w w . j av a 2 s.c o m*/ Menu addItem(String text, String actionCommand, ActionListener listener) { JMenuItem item = new JMenuItem(text); item.setActionCommand(actionCommand); item.addActionListener(listener); JMenu lastMenu = getMenu(getMenuCount() - 1); lastMenu.add(item); return this; }
From source file:cz.lidinsky.editor.Menu.java
Menu addItem(String text, String actionCommand, ActionListener listener, char mnemonic) { JMenuItem item = new JMenuItem(text); item.setActionCommand(actionCommand); item.addActionListener(listener); item.setMnemonic(mnemonic);//from w w w.j a v a2 s. c om JMenu lastMenu = getMenu(getMenuCount() - 1); lastMenu.add(item); return this; }
From source file:io.github.jeddict.relation.mapper.widget.table.BaseTableWidget.java
@Override protected List<JMenuItem> getPopupMenuItemList() { List<JMenuItem> menuList = super.getPopupMenuItemList(); JMenuItem menuItem = new JMenuItem("Create Secondary Table"); menuItem.addActionListener((ActionEvent e) -> { Entity entity = this.getBaseElementSpec().getEntity(); String secondaryTableName = JOptionPane.showInputDialog( (Component) BaseTableWidget.this.getModelerScene().getModelerPanelTopComponent(), "Please enter secondary table name"); if (entity.getTable(secondaryTableName) == null) { //check from complete table list SecondaryTable secondaryTable = new SecondaryTable(); secondaryTable.setName(secondaryTableName); entity.addSecondaryTable(secondaryTable); ModelerFile parentFile = BaseTableWidget.this.getModelerScene().getModelerFile().getParentFile(); DBUtil.openDBModeler(parentFile); JeddictLogger.recordDBAction("Create Secondary Table"); } else {//www.ja v a 2 s. co m JOptionPane.showMessageDialog( (Component) BaseTableWidget.this.getModelerScene().getModelerPanelTopComponent(), "Table already exist"); } }); menuList.add(0, menuItem); return menuList; }
From source file:net.landora.video.ui.UIAddon.java
public JPopupMenu createPopupMenu(Collection<?> context) { MultiValueMap valuesByClass = UIUtils.createCompleteContextByClass(context); List<UIAction<?>> actionsToUse = new ArrayList(); for (UIAction<?> action : actions) { Class<?> clazz = action.getRequiredClass(); Collection<?> col = valuesByClass.getCollection(clazz); if (col == null || col.isEmpty()) { continue; }//from w ww . ja va 2 s . com if (action.isMultipuleObjectSupport() || col.size() == 1) { actionsToUse.add(action); } } if (actionsToUse.isEmpty()) { return null; } JPopupMenu menu = new JPopupMenu(); for (UIAction<?> action : actionsToUse) { JMenuItem item = new JMenuItem(action.getName()); item.addActionListener( new UIActionAction(action, valuesByClass.getCollection(action.getRequiredClass()))); menu.add(item); } return menu; }
From source file:SwingMenus.java
public void init() { ML ml = new ML(); CMIL cmil = new CMIL(); safety[0].setActionCommand("Guard"); safety[0].setMnemonic(KeyEvent.VK_G); safety[0].addItemListener(cmil);//from w w w . j a va 2 s .c om safety[1].setActionCommand("Hide"); safety[1].setMnemonic(KeyEvent.VK_H); safety[1].addItemListener(cmil); other[0].addActionListener(new FooL()); other[1].addActionListener(new BarL()); other[2].addActionListener(new BazL()); FL fl = new FL(); for (int i = 0; i < flavors.length; i++) { JMenuItem mi = new JMenuItem(flavors[i]); mi.addActionListener(fl); m.add(mi); // Add separators at intervals: if ((i + 1) % 3 == 0) m.addSeparator(); } for (int i = 0; i < safety.length; i++) s.add(safety[i]); s.setMnemonic(KeyEvent.VK_A); f.add(s); f.setMnemonic(KeyEvent.VK_F); for (int i = 0; i < file.length; i++) { file[i].addActionListener(fl); f.add(file[i]); } mb1.add(f); mb1.add(m); setJMenuBar(mb1); t.setEditable(false); Container cp = getContentPane(); cp.add(t, BorderLayout.CENTER); // Set up the system for swapping menus: b.addActionListener(new BL()); b.setMnemonic(KeyEvent.VK_S); cp.add(b, BorderLayout.NORTH); for (int i = 0; i < other.length; i++) fooBar.add(other[i]); fooBar.setMnemonic(KeyEvent.VK_B); mb2.add(fooBar); }
From source file:MainClass.java
public MainClass() { popup = new JPopupMenu(); ActionListener menuListener = new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("Popup menu item [" + event.getActionCommand() + "] was pressed."); }//from w w w .j av a 2 s . c om }; JMenuItem item; popup.add(item = new JMenuItem("Left", new ImageIcon("left.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Center", new ImageIcon("center.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Right", new ImageIcon("right.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Full", new ImageIcon("full.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.addSeparator(); popup.add(item = new JMenuItem("Settings . . .")); item.addActionListener(menuListener); popup.setLabel("Justification"); popup.setBorder(new BevelBorder(BevelBorder.RAISED)); popup.addPopupMenuListener(new PopupPrintListener()); addMouseListener(new MousePopupListener()); }
From source file:Main.java
public Main() { popup = new JPopupMenu(); ActionListener menuListener = new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("Popup menu item [" + event.getActionCommand() + "] was pressed."); }/*from w w w . j a v a 2s .co m*/ }; JMenuItem item; popup.add(item = new JMenuItem("Left", new ImageIcon("left.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Center", new ImageIcon("center.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Right", new ImageIcon("right.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Full", new ImageIcon("full.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.addSeparator(); popup.add(item = new JMenuItem("Settings . . .")); item.addActionListener(menuListener); popup.setLabel("Justification"); popup.setBorder(new BevelBorder(BevelBorder.RAISED)); popup.addPopupMenuListener(new PopupPrintListener()); addMouseListener(new MousePopupListener()); }