Results 1 to 6 of 6

Thread: Confused about JMenuItem class of java

  1. #1
    Join Date
    Dec 2009
    Posts
    41

    Confused about JMenuItem class of java

    Hello Guys,

    I have one query to discuss with you. My query is related to the JMenuItem class of java. I am not getting the what is the use of JMenuItem class of java. I don't have any knowledge about it's methods and constructor declaration. If you posses sound knowledge about the JMenuItem class of java, then please let me know the same with proper example. Your help would be greatly appreciable.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Confused about JMenuItem class of java

    A JMenuItem used for the implementation of an item in a menu. A menu item is essentially a button sitting in a list. When the user selects the "button", the action associated with the menu item is performed. A JMenuItem contained in a JPopupMenu performs exactly that function. This java class provides standard Look and Feel (L&F) renditions. This java class is basically extended from the 'javax.swing.AbstractButton' package.

  3. #3
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Confused about JMenuItem class of java

    Hi,

    I recommend you to go through the following constructors of JMenuItem class of java:
    1. JMenuItem(String text1, int nr)
    2. JMenuItem(Action ac1)
    3. JMenuItem(String text1, Icon icon1)
    4. JMenuItem(String text1)
    5. JMenuItem(Icon icon1)

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    Re: Confused about JMenuItem class of java

    Please following example of java, which will help you to know about the JMenuItem class:
    Code:
    import javax.swing.JMenuItem;
    import javax.swing.KeyStroke;
    
    public class JMenuItemDM {
    
      public static void main(final String args[]) {
        JFrame VO = new JFrame("MenuSample Example");
        VO.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JMenuBar menuBar = new JMenuBar();
    
        JMenu fileMenu = new JMenu("File");
        fileMenu.setMnemonic(KeyEvent.VK_F);
        menuBar.add(fileMenu);
        
        JMenuItem PMIT = new JMenuItem("Paste", KeyEvent.VK_P);
        KeyStroke ctrlVKeyStroke = KeyStroke.getKeyStroke("control V");
        PMIT.setAccelerator(ctrlVKeyStroke);
        PMIT.setEnabled(false);
        fileMenu.add(PMIT);
    
        VO.setJMenuBar(menuBar);
        VO.setSize(250, 250);
        VO.setVisible(true);
      }
    }

  5. #5
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Confused about JMenuItem class of java

    Hi friend,

    Following are some methods of JMenuItem class along with different parameter list:
    • setAccelerator(KeyStroke ks1)
    • removeMenuKeyListener(MenuKeyListener Ml1)
    • removeMenuDragMouseListener(MenuDragMouseListener MDl1)
    • processMenuKeyEvent(MenuKeyEvent me)
    • menuSelectionChanged(boolean bl1)

  6. #6
    Join Date
    May 2008
    Posts
    2,297

    Re: Confused about JMenuItem class of java

    Hello friend,

    If you want to create separating Menu using JMenuItem class, then please review following java example:
    Code:
    import javax.swing.JMenuItem;
    import javax.swing.JMenu;
    import javax.swing.JSeparator;
    
    public class JMIMain {
      public static void main(String[] argnv) throws Exception {
        JMenu menu03 = new JMenu("Menu Label");
    
        JMenuItem item01 = new JMenuItem("Item Label");
        menu03.add(item1);
    
        menu03.add(new JSeparator());
    
        JMenuItem item02 = new JMenuItem("Item Label");
        menu03.add(item02);
      }
    }

Similar Threads

  1. Converting java class to java bean class
    By Ucchal in forum Software Development
    Replies: 6
    Last Post: 09-08-2010, 10:24 AM
  2. Confused with GraphicsDevice class of java
    By Gokul20 in forum Software Development
    Replies: 5
    Last Post: 27-02-2010, 08:09 AM
  3. Confused with JPopupMenu class
    By Bottlenecked in forum Software Development
    Replies: 5
    Last Post: 16-02-2010, 09:27 AM
  4. Confused about JRootPane class of java
    By Mithun Seth in forum Software Development
    Replies: 5
    Last Post: 15-02-2010, 01:38 PM
  5. Confused about PrintWriter class of Java
    By ScarFace 01 in forum Software Development
    Replies: 5
    Last Post: 21-01-2010, 09:09 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,287,908.56435 seconds with 17 queries