aspose file tools*
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
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: 19785
    
  20

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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JComboBox Action Issues.