Results 1 to 6 of 6
Thread: Multiple JComboBox's
- 08-19-2012, 09:51 PM #1
Member
- Join Date
- Aug 2012
- Location
- Ohio
- Posts
- 3
- Rep Power
- 0
Multiple JComboBox's
Hello, I'm attempting to use multiple JComboBox's in the same class. The boxes display on screen as planned, however, when handling user input, I'm not sure how to tell which combo box was selected from.
Here is a screenshot of my program with the boxes being displayed, as they should:

How would I go about differentiating between a selection made in the "Floor Tiles" box and a selection made in one of the other boxes?
If possible it would be nifty to be able to make the difference based on what the name of the combo box is.
For example:
JComboBox floorBox = new JComboBox(...);
JComboBox decorativeBox = new JComboBox(...);
JComboBox gameplayBox = new JComboBox(...);
and then use a switch statement or something to say if the name is "floorBox", do this with "floorBox's" selection.
I'm relatively new to Java and programming in general, so any help or advice in greatly appreciated! Thanks!
-
Re: Multiple JComboBox's
It's simple. when the save button is pressed and you need to extract the information out of the JComboBox, you could simply use the JComboBox variable name. For instance, assuming that they hold Strings, you could do:
Java Code:// in the save JButton's ActionListener's actionPerformed method: String floorTile = floorBox.getSelectedValue().toString(); String decorativeTile = decorativeBox.getSelectedValue().toString(); String gamePlayTile = gameplayBox.getSelectedValue().toString();
- 08-19-2012, 11:51 PM #3
Member
- Join Date
- Aug 2012
- Location
- Ohio
- Posts
- 3
- Rep Power
- 0
Re: Multiple JComboBox's
Thank you for your response, however I'm not sure this does what I wish to accomplish. I probably explained it a little wrong lol. I'm needing to perform an action when a selection in one of the JComboBox's is made. The action performed would be different depending on which combo box was selected from, and the selection that was made. How would I go about setting up my itemStateChanged() method to do something different depending on which combo box was selected from, and the selection that was made?
-
Re: Multiple JComboBox's
- 08-20-2012, 01:48 AM #5
Member
- Join Date
- Aug 2012
- Location
- Ohio
- Posts
- 3
- Rep Power
- 0
-
Similar Threads
-
Multiple JComboBox
By LiLGuy2004 in forum AWT / SwingReplies: 5Last Post: 07-28-2012, 05:05 AM -
One process open multiple threads on multiple CPUs
By kfcnhl in forum Threads and SynchronizationReplies: 2Last Post: 12-12-2011, 08:27 AM -
multiple Data from Jsp that having same name of multiple input tage to servlet
By rahul9323.2007@gmail.com in forum Advanced JavaReplies: 0Last Post: 07-29-2011, 01:00 PM -
problem w/ multiple jcombobox
By garagumo in forum Advanced JavaReplies: 0Last Post: 05-06-2011, 06:47 AM -
Activate JComboBox 1 when object is selected in JComboBox 2...
By bahumbaba in forum AWT / SwingReplies: 2Last Post: 12-10-2009, 01:58 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks