Results 1 to 6 of 6

Thread: What is the use of JMenu class?

  1. #1
    Join Date
    Dec 2009
    Posts
    48

    What is the use of JMenu class?

    Hi All,

    I am quit confused about the some concepts of java language. For me the class concepts of the java seems very difficult to understand as compare to C++ programming. A 'JMenu class' is one of them. I don't have any idea about the use of JMenu class from the advanced java. So if you have sound knowledge about the JMenu class, then please let me know that. I would appreciate your any help over 'JMenu class'.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: What is the use of JMenu class?

    Hi,

    The JMenu class is used for the implementation of menu. In addition to JMenuItems, a JMenu can also contain JSeparators. In essence, a menu is a button with an associated JPopupMenu. When the "button" is pressed, the JPopupMenu appears. If the "button" is on the JMenuBar, the menu is a top-level window. If the "button" is another menu item, then the JPopupMenu is "pull-right" menu.

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

    Re: What is the use of JMenu class?

    Hi Friend,

    Please review following example of 'JMenu class'. This java program code will demonstrate you the use of JMenu class along with it's methods:
    Code:
    import javax.swing.JSeparator;
    import javax.swing.JMenu;
    
    public class JMenuDemo1 extends JFrame 
    {
      public JMenuDemo1() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JMenuBar barT = new JMenuBar();
        JMenu menuT = new JMenu("File");
        barT.add(menuT);
    
        menuT.add(new JMenuItem("Close"));
        menuT.add(new JSeparator()); 
        menuT.add(new JMenuItem("Exit"));
    
        setJMenuBar(barT);
        getContentPane().add(new JLabel("A placeholder"));
    
        pack();
        setSize(400, 300);
        setVisible(true);
      }
    
      public static void main(String arg[]) {
        new JMenuDemo1();
      }
    }

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

    Re: What is the use of JMenu class?

    To use properties of JMenu class of class, for that you should be aware about following it's methods:
    • setPopupMenuVisible(boolean bln)
    • setModel(ButtonModel newMdl)
    • setMenuLocation(int x01, int y01)
    • setComponentOrientation(ComponentOrientation cmporn)
    • setAccelerator(KeyStroke ksk)
    • processKeyEvent(KeyEvent kevt)

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

    Re: What is the use of JMenu class?

    Hello friend,

    See if something below code can help you to know about JMenu class or not:
    Code:
    JMenuItem newMenuItem01 = new JMenuItem("New");
    fileMenu.add(newMenuItem01);
    
    JMenuItem openMenuItem01 = new JMenuItem("Open");
    fileMenu.add(openMenuItem01);
    
    JMenuItem closeMenuItem01 = new JMenuItem("Close");
    fileMenu.add(closeMenuItem01);
    fileMenu.addSeparator();
    
    JMenuItem saveMenuItem01 = new JMenuItem("Save");
    fileMenu.add(saveMenuItem01);
    fileMenu.addSeparator();
    
    JMenuItem exitMenuItem01 = new JMenuItem("Exit");
    fileMenu.add(exitMenuItem01);

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

    Re: What is the use of JMenu class?

    Please review following constructors of JMenu class which are used to create menu. While the type of JMenu is depends upon parameters which are supplied to it's constructors:
    1. JMenu(String st, boolean bln): This constructor of JMenu is used for the creation of a new JMenu with the apecified string as a text.
    2. JMenu(String st): This constructor of JMenu is used for the creation of a JMenu using given string.
    3. JMenu(Action ac): This constructor of JMenu is used for the creation of a JMenu fpr which action proerties are Action supplied.
    4. JMenu(): This constructor of JMenu is used for the creation menu without any text.

Similar Threads

  1. Replies: 8
    Last Post: 08-10-2011, 11:06 PM
  2. Class JMenu.AccessibleJMenu of java
    By Sonam Goenka in forum Software Development
    Replies: 5
    Last Post: 16-02-2010, 01:46 PM
  3. Replies: 5
    Last Post: 12-02-2010, 06:23 PM
  4. Ultra solid drives:Imation M-Class and S-Class
    By Regina in forum Portable Devices
    Replies: 1
    Last Post: 03-04-2009, 10:34 AM
  5. Good news for CBSE CLASS X & CLASS IX - visit learnnext
    By surya_expert in forum Education Career and Job Discussions
    Replies: 0
    Last Post: 13-12-2008, 12:09 PM

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,713,907,449.84671 seconds with 16 queries