Results 1 to 5 of 5

Thread: JMenu ...Can't remember

  1. #1

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    JMenu ...Can't remember

    I can't remember how to get subcategories with JMenu's. If anyone knows how, please let me know. I'll post a screenshot so you know exactly what I'm talking about.

  2. #2

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: JMenu ...Can't remember

    Never mind, I figured it out.

  3. #3
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: JMenu ...Can't remember

    Quote Originally Posted by System_Error
    Never mind, I figured it out.
    Why don't you post the solution so maybe someone else could find it in the future


    Has someone helped you? Then you can Rate their helpful post.

  4. #4

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: JMenu ...Can't remember

    All you do, is add a JMenu, to a JMenu!
    I'll demonstrate below:

    Code:
    JMenuBar menuBar = new JMenuBar();
    
    //Normal menu with no submenu's
    JMenu fileMenu = new JMenu("File");
    fileMenu.add(new JMenuItem("Exit");
    
    //this will have submenu's
    JMenu format = new JMenu("Format");
    format.add(new JMenuItem("Font"));
    
    /*  start making the submenu, by creating
     *  a menu, and adding items to it...Once
     *  finished, add the color menu to the format 
     *  menu
     */
    JMenu color = new JMenu("Color");
    color.add(new JMenuItem("Red"));
    color.add(new JMenuItem("Blue"));
    
    //add the menu to the other menu
    format.add(color);
    
    menuBar.add(fileMenu);
    menuBar.add(format);

  5. #5
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: JMenu ...Can't remember

    Yes quite simple.
    Code:
     import java.awt.*;
     import javax.swing.*; 
     import java.awt.event.*; 
    
     public class X{ 
      public static void main(String[] args){ 
    
      JFrame jf = new JFrame("JMenu Example"); 
      Container c = jf.getContentPane(); 
      JMenuBar jmb = new JMenuBar(); 
      JMenu jm = new JMenu("File");
      JMenu sendto = new JMenu("Send To"); 
      JMenuItem print = new JMenuItem("Print"); 
      JMenuItem exit = new JMenuItem("Exit"); 
      jf.setJMenuBar(jmb);
      jmb.add(jm); 
      jm.add(sendto);
      jm.add(print);
      jm.add(exit);
     
      // add sub menu
      sendto.add(new JMenuItem("3 1/2 Floppy(A)")); 
      sendto.add(new JMenuItem("DeskTop")); 
      sendto.add(new JMenuItem("Web Publishing Wizard")); 
     
      jf.addWindowListener(new WindowAdapter(){
        public void windowClosing(WindowEvent we){
           System.exit(0); 
       }
      });
     
      jf.setSize(400,300); 
      jf.setVisible(true); 
    
      }
     }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width