Results 1 to 3 of 3
Thread: [SOLVED] JComboBox
- 04-26-2009, 09:00 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 11
- Rep Power
- 0
[SOLVED] JComboBox
Hi there,
My app has got an array of JComboBox named comboBox and they have actionListeners attached. The question is how do I determine the array index of the comboBox that fired the event?
I need to know so that I can transfer the chosen value in comboBox to a JTextField with an identical array index.
Thanks.
-
You can get the reference to the currently selected JComboBox via the actionPerformed method's ActionEvent parameter by calling getSource() on it. Then you can iterate through the combo box array using this object to determine which array item is the selected combo box. For example:
Java Code:public void actionPerformed(ActionEvent e) { JComboBox selectedComboBox = (JComboBox)e.getSource(); int comboIndex = -1; for (int i = 0; i < comboBox.length; i++) { if (comboBox[i] == selectedComboBox) { comboIndex = i; } } // do what needs to be done with comboIndex here }Last edited by Fubarable; 04-26-2009 at 09:11 PM.
- 04-28-2009, 02:14 AM #3
Similar Threads
-
JComboBox
By pinks_70986 in forum New To JavaReplies: 2Last Post: 02-19-2009, 05:26 PM -
I need help with JComboBox
By eva21 in forum New To JavaReplies: 1Last Post: 11-28-2008, 10:05 PM -
JCombobox
By daniel50096230 in forum NetBeansReplies: 1Last Post: 09-21-2008, 12:23 PM -
JComboBox
By Fosters in forum AWT / SwingReplies: 0Last Post: 08-10-2008, 01:22 PM -
jcombobox
By Freddie in forum AWT / SwingReplies: 4Last Post: 05-11-2007, 12:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks