Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Joining two menus into one?

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Joining two menus into one?

    I have a situation where a large part of my Swing Application menu wants to be generated automatically by an Xtext DSL (Domain Specific Language). However, not all of it.

    I'm pretty sure that it will be straightforward for me to have the code generation create an independent class with those menu entries. However I would like to join that with the rest of the menu that I will just be maintaining by hand as it won't be changing very often.

    Anyone ever done this that can recommend a good approach?

    Thanks,

    DL


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,297
    Thanks
    180
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: Joining two menus into one?

    If I understand your question, to dynamically add elements on the fly to a JMenu you can add a MenuListener to the JMenu. This will allow you to add/remove elements when the menu is selected/deselected.

  3. The Following User Says Thank You to copeg For This Useful Post:

    Digital Larry (October 24th, 2013)

  4. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Joining two menus into one?

    Quote Originally Posted by copeg View Post
    If I understand your question, to dynamically add elements on the fly to a JMenu you can add a MenuListener to the JMenu. This will allow you to add/remove elements when the menu is selected/deselected.
    Well, I don't really need to do it dynamically, but that could work. Here's an example of how I'm currently doing it:

    		JMenu mnPots = new JMenu("Pots");
    		menuBar.add(mnPots);
     
    		final JMenuItem mntmPot0 = new JMenuItem("Pot 0");
    		mntmPot0.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				SpinCADBlock pcB = new Pot0CADBlock(50, 100);
    				dropBlock(panel, pcB);
    			}
    		});
    		mnPots.add(mntmPot0);

    So I guess I already am adding them "on the fly", although this code is just in the frame initialization code. Thanks for the answer!

Similar Threads

  1. Excited about joining here.
    By StephenHawking9 in forum Member Introductions
    Replies: 1
    Last Post: June 19th, 2012, 01:29 AM
  2. Replies: 9
    Last Post: January 12th, 2012, 04:03 PM
  3. Crescent IT Solutions - I am newly joining this forum to share information
    By crescentitsolutions in forum Member Introductions
    Replies: 2
    Last Post: August 6th, 2011, 01:34 PM
  4. i am joining in a new company
    By ittoolvardhan in forum Member Introductions
    Replies: 2
    Last Post: September 6th, 2010, 02:54 AM
  5. Menu of Menus Help
    By Strivelli in forum Java Theory & Questions
    Replies: 10
    Last Post: June 5th, 2010, 02:40 PM