About 284,000 results
Open links in new tab
  1. How to Use Menus (The Java™ Tutorials > Creating a GUI With Swing

    Inserts a menu item or separator into the menu at the specified position. The first menu item is at position 0, the second at position 1, and so on. The JMenuItem and String arguments are treated the same as in the corresponding add methods. void remove(JMenuItem) void remove(int) void removeAll() Removes the specified item(s) from the menu.

  2. Java Swing | JMenuBar | GeeksforGeeks

    May 20, 2022 · JMenuBar, JMenu and JMenuItems are a part of Java Swing package. JMenuBar is an implementation of menu bar . the JMenuBar contains one or more JMenu objects, when the JMenu objects are selected they display a popup showing one or more JMenuItems .

  3. Java AWT MenuItem & Menu - GeeksforGeeks

    Nov 13, 2023 · Java JCheckBoxMenuItem is a GUI component in Swing that extends the JMenuItem class. It represents a Menu item with a checkbox that can be checked or unchecked. JCheckBoxMenuItem is often used in menu systems to allow users to toggle options.

  4. How to make a JMenu item do something when it's clicked

    JMenuItem menuItem = new JMenuItem(new MyAction()); ... public class MyAction extends AbstractAction { public MyAction() { super("My Menu Item"); } public void actionPerformed(ActionEvent e) { // Button pressed logic goes here } } Note that everything I said above also applies to JButton.

  5. How do I create a right click context menu in Java Swing?

    Jul 25, 2018 · To make a right click popup menu simply create a JPopupMenu. JMenuItem anItem; public PopUpDemo() { anItem = new JMenuItem("Click Me!"); add(anItem); Then, all you need to do is add a custom MouseListener to the components you would like the menu to popup for. public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) doPop(e);

  6. Menus and toolbars in Java Swing - ZetCode

    Jan 10, 2023 · In this part of the Java Swing tutorial, we are going to work with menus and toolbars. In the examples we will create regular menus, submenus, checbox menu items, radio button menu items, popup menus, and toolbars. A menu is a group of commands located in a menubar. A toolbar has buttons with some common commands in the application.

  7. swing - java action listener on menu, and not on menu item - Stack Overflow

    Feb 20, 2012 · JMenu menu = new JMenu("MyMenu"); menu.addActionListener(new ActionListener(){...}); But, it is not intended to be used this way: JMenu ignores ActionEvent . You should use MenuEvent and MenuListener instead.

  8. How to Create Menu in Swing - zentut

    In order to create menu items in Swing, you need to create new instances of JMenuItem and set different properties for them. You can create menu item with both text and icon. Here are the constructors of JMenuItem: Creates a JMenuItem instance without icon or text. Creates a JMenuItem instance with a given icon.

  9. Swing Menu in Java - Online Tutorials Library

    Swing Menu in Java - Learn how to create and implement menus in Java Swing. Explore different types of menus, including JMenus, JPopupMenus, and more.

  10. Java JMenuItem & JMenu - Tpoint Tech

    Mar 17, 2025 · The JMenuBar class is used to display menubar on the window or frame. It may have several menus. The object of JMenu class is a pull down menu component which is displayed from the menu bar. It inherits the JMenuItem class. The object of JMenuItem class adds a simple labeled menu item.

Refresh