This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JComboBox Action Issues. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JComboBox Action Issues." Watch "JComboBox Action Issues." New topic
Author

JComboBox Action Issues.

Ben Jass
Ranch Hand

Joined: Sep 25, 2010
Posts: 76
Hey guys, I'm having trouble using an actionListener with this JComboBox. Whenever I try to receive the selected index, it always returns "0" no matter what is selected inside the JComboBox.

Creation of the JComboBox:


ActionHandler:


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

You shouldn't create a new Gui instance but use the existing one. Because you create a new Gui instance you also create a new JComboBox for it, and it's this new JComboBox that you're getting the selected index of.

Maybe even better, use event.getSource():


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ben Jass
Ranch Hand

Joined: Sep 25, 2010
Posts: 76
Wow, that worked. I have no idea how though? Can you explain what event.getSource() does? In my eyes it just looks like your creating an instance of JComboBox and casting JComboBox objects on it...and then I get lost...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JComboBox Action Issues.
 
Similar Threads
how to implement MVC?
JLabel constantly repainting itself
calendar
Dynamic JList generation in Swing
Swing Calender, ComboBox and timer questions