This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JComboBox

 
Rick Gentry
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got a JComboBox and I want to recieve an event when a new item is selected. I've tried an ActionListener and an ItemListener. Neither one wants to work for me. Any help?
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest that you post some relevant code, and somebody may be able to help.
cheers
 
Rick Gentry
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's see here relevant code.....I don't have any, that's what I'm asking for help with. All I know is it's going to go something like this.

That's about as relevant as I can get without an answer.
 
Don Kiddick
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need an ItemListener.
D.
 
Rick Gentry
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I had an ItemListener.

Changing the selected item activates itemStateChanged but e.getSource() doesn't return the JComboBox.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Swing...
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rick Gentry:
Yeah, I had an ItemListener.

Changing the selected item activates itemStateChanged but e.getSource() doesn't return the JComboBox.

Yes it does. But you have to cast it.
 
Rick Gentry
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it work, I was declaring the box outside the function but finished declaring it inside. So the box was null when it got to the ItemEvent. So in short I made a stupid mistake that I've made before and I'm sure I'll make again. Thanks for the help though.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic