File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to create list of Menu list Item dynamically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to create list of Menu list Item dynamically" Watch "How to create list of Menu list Item dynamically" New topic
Author

How to create list of Menu list Item dynamically

jacob raja
Greenhorn

Joined: Feb 20, 2007
Posts: 7
I need to create the menu list dynamically, i visited this link and http://wiki.eclipse.org/index.php/FAQ_How_do_I_make_menus_with_dynamic_contents%3F and came to know about IMenuManager and IMenuListener. kindly help me to know how it works through an example


Luv<br />jacob Marshall
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
They have given a very simple example on the Eclipse wiki.
Try out their example. Set up a GUI with a menu with three possible items, (let's call it MenuFrame) which have to be fields rather than local variables in the constructor.
Set up something like this:-

Set up some sort of criterion for setting "daytime" and "night time," maybe by passing "D" or "N" as a command-line argument. See what comes of it.

Go back and set up another class with "day" and "night" buttons. Use them to instantiate new MenuFrame objects, size and display them. See what happens. It's not at all difficult.

Another way you can handle menus is to use their setEnabled() method. Depending whether it is "day" or "night" you can enable them or disable them.
  • Advantage: your menu items are always there so users can still see them.
  • Disadvantage: I don't think there is a "setEverythingEnabled" method, so you have to reset them individually.

  • Good luck. If it doesn't work, come back.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 39478
        
      28
    More about the Eclipse wiki example. Do they say where the classes IMenuManager and IMenuListener come from? I can't seem to find them in the Java 6 API website. You will have to work out how to get those classes, or you can't get the menu changes to work.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 39478
        
      28
    . . try the remove(), removeAll() and add() methods in the JMenu class.
    jacob raja
    Greenhorn

    Joined: Feb 20, 2007
    Posts: 7
    thank you Campbell Ritchie, was able to Display menu Items dynamically, Was able to display menus(Dynamicaly) using IMenuManager and IMenuListerner. create the menu -> File using IMenuManager and add a listerner to it and add the sub menus in the listerner.

    IMenuManager and IMenuListerner are present in JFace using this i was able to display MenuItems dynamically
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 39478
        
      28
    Well done. Thank you for the information about JFace.

    CR
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: How to create list of Menu list Item dynamically