The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing  [141 examples] > Menus  [8 examples]

e809. Separating Menu Items in a Menu

A separator typically appears as a horizontal line. It is used to group related sets of menu items in a menu.
    // Create a menu
    JMenu menu = new JMenu("Menu Label");
    
    // Add a menu item
    JMenuItem item1 = new JMenuItem("Item Label");
    menu.add(item1);
    
    // Add separator
    menu.add(new JSeparator());
    
    // Add another menu item
    JMenuItem item2 = new JMenuItem("Item Label");
    menu.add(item2);

 Related Examples
e808. Creating a JMenuBar, JMenu, and JMenuItem Component
e810. Creating a Popup Menu
e811. Creating a Popup Menu with Nested Menus
e812. Forcing a Popup Menu to Be a Heavyweight Component
e813. Getting the Currently Selected Menu or Menu Item
e814. Creating a Menu Item That Listens for Changes to Its Selection Status
e815. Listening for Changes to the Currently Selected Menu or Menu Item

See also: Actions    JButton    JCheckBox    JComboBox    JDesktop and JInternalFrame    JFrame, JWindow, JDialog    JLabel    JList    JProgressBar    JRadioButton    JScrollPane    JSlider    JSpinner    JSplitPane    JTabbedPane    JToolBar    Keystrokes and Input Maps    Layout    Look and Feel    Progress Monitor    The Screen    Tool Tips    UI Default Values   


© 2002 Addison-Wesley.