Results 1 to 2 of 2
  1. #1
    arulmozs is offline Member
    Join Date
    Oct 2009
    Posts
    7
    Rep Power
    0

    Default Create JMenuBar using DataBase

    Pls any help me how to create JMenuBar using database dynamic

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    I would separate the creation of the menu bar from the database part. start with getting a kind of "menu definition" data structure working to feed the creation of the jmenubar

    for example a "MenuBean"
    String label
    String shortcutKey
    List<MenuItemBean> titems

    and a "MenuItemBean"
    String type; // will be used to determine what Swing menu item will be created (JMenuItem, JmenuSepartor, JCheckboxMenuItem, etc)
    String label
    String actionClass // the full package class to the handler when this menu item is selected.


    where the action class is a string name for the handler class which would be something that implements the ActionListener interface (or any other listeners the JMenuItem wants to invoke).
    alternatively we could have one big handler class and define the method to be invoked here. This is assuming we have the handler code for the menu item ahead of time, (as it the case if we wanted a dynamic JMenu from the database to show only the things the current user is allowed to do) when we create the JMenuItem we would need to either look up the object instance (e.g. spring framework, bean factory), or reflectively create it.

    If we wanted to have the dynamic menu fire off a dynamic action, that is more complicated, you would need to have all jmenu items generate an event into a klnd of internal event bus, so as to provide hooks for something else to somehow act on that event.

    Im sure iteration though experimentation will flush out other details of what is needed for these MenuBean and MenuItemBean classes. Note all fields here in these plain bean classes are just strings, ints,(simple types). once you have a test case able to create a JMENU from a List<MenuBean> , then it should be more obvious how to have these beans mapped to a database, using the database object mapper of your choice (jdbc, ibatis, hibernate, other?). Perhaps a menu and a menu_item table, with an additional menu_id property to link it to menu table.

Similar Threads

  1. Replies: 2
    Last Post: 02-11-2009, 05:43 AM
  2. Create Calander
    By cheecoo in forum Java Applets
    Replies: 5
    Last Post: 06-12-2008, 04:50 AM
  3. Create a new variable
    By mathias in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:48 AM
  4. Create XML From XSD
    By Jack in forum XML
    Replies: 1
    Last Post: 07-09-2007, 01:56 AM

Posting Permissions

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