Results 1 to 6 of 6
  1. #1
    jiffi is offline Member
    Join Date
    Oct 2011
    Posts
    79
    Rep Power
    0

    Default Java DropDown Menu (JCombo Box)

    hey guys
    Ok so I was wondering if it was possible to add items to a JCombo Box as the user creates new arrays:
    Say you have this.

    Java Code:
    mainMenu = JOptionPane.showInputDialog(null,"Choose an action", "Menu",//main menu
                    JOptionPane.QUESTION_MESSAGE,null, new Object [] 
    {"Manage Credit Cards","Manage Work","Manage Bank", "Save","Save as...", "Open", "Customize Program", "Exit"}, "");
    Now the user "does" an action, that should add an option to that menu. Is that possible?
    I know how to change the names what you see, but can I add a new option?

    If what you saw there were arrays, and I wanted the user to have the option to choose from a new array everytime he added one, is that possible?
    (note: I am only using one method (public static void main (String [] args) )

    thanks
    Last edited by jiffi; 11-05-2011 at 11:52 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Java DropDown Menu (JCombo Box)

    Your best bet is to use an actual JComboBox, not a non-reachable one in the JOptionPane. Then use a DefaultComboBoxModel for your combobox's model. The JComboBox tutorial will show you the way.

  3. #3
    jiffi is offline Member
    Join Date
    Oct 2011
    Posts
    79
    Rep Power
    0

    Default Re: Java DropDown Menu (JCombo Box)

    Do I need different methods to do this? Because like I said, I only know how to work with the main method, which is quite a handicap at the time…

    edit: Apparently, it does use different methods. Thanks anyways
    Last edited by jiffi; 11-05-2011 at 01:07 PM.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Java DropDown Menu (JCombo Box)

    Quote Originally Posted by jiffi View Post
    Do I need different methods to do this? Because like I said, I only know how to work with the main method, which is quite a handicap at the time…

    edit: Apperently, it does use different methods. Thanks anyways
    um... time to learn some Java.

  5. #5
    jiffi is offline Member
    Join Date
    Oct 2011
    Posts
    79
    Rep Power
    0

    Default Re: Java DropDown Menu (JCombo Box)

    I am kinda stuck with my school curriculum, learning java by yourself is not the easiest thing to do.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Java DropDown Menu (JCombo Box)

    Quote Originally Posted by jiffi View Post
    I am kinda stuck with my school curriculum, learning java by yourself is not the easiest thing to do.
    I know exactly what you mean, because that's how most of us, including me, have learned it: we taught ourselves. With a little effort and a sense of adventure, you can too!

Similar Threads

  1. Replies: 1
    Last Post: 08-12-2011, 05:55 AM
  2. dropdown menu getting overlapped issue
    By jeev81 in forum Advanced Java
    Replies: 0
    Last Post: 02-02-2011, 12:03 PM
  3. Fill a menu dynamically when menu is shown
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 04:47 PM
  4. React to menu action and checkbox menu
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-27-2008, 07:50 PM
  5. Replies: 7
    Last Post: 05-09-2008, 07:54 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
  •