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: Getting the Selected Value in JComboBox

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default [SOLVED ] Getting the Selected Value in JComboBox

    So I'm looking for a way to check if the certain value of a JComboBox is selected.

    I've tried event.getSource() == comboBox.getSelectedItem()

    But it's not going to work since I don't specify which value I want it to equal to.

    If my list is:

    JComboBox
    Hello
    Hi
    Testing

    I know Hello has a int value of = 0;

    How would I check if the Hello value is highlighted?
    Last edited by aStudentofJava; March 4th, 2012 at 08:15 PM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Getting the Selected Value in JComboBox

    As always, the API is your best friend: JComboBox (Java Platform SE 6)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Feb 2012
    Posts
    58
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: [SOLVED ] Getting the Selected Value in JComboBox

    Very simple:
    - cast the selected item object to a String object.
    - compared the casted String to the "Hello" string.

Similar Threads

  1. How to Delete selected table data from DB???? HELP
    By lanepulcini in forum JDBC & Databases
    Replies: 0
    Last Post: February 21st, 2012, 07:07 PM
  2. Add extended JPanel on selected index change of JComboBox
    By mikejr76 in forum AWT / Java Swing
    Replies: 3
    Last Post: February 20th, 2012, 10:32 PM
  3. help with user selected section has no available seat applet
    By chonch in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 31st, 2011, 07:39 AM
  4. Problem getting selected item as string from JComboBox
    By lost in forum AWT / Java Swing
    Replies: 1
    Last Post: October 26th, 2010, 03:22 AM
  5. Change of color for selected text in AWT
    By venkyInd in forum AWT / Java Swing
    Replies: 2
    Last Post: April 9th, 2010, 03:51 AM