• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JComboBox Action Issues.

 
Ben Jass
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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():
 
Ben Jass
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic