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 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" Watch "JComboBox" New topic
Author

JComboBox

Rick Gentry
Ranch Hand

Joined: Dec 14, 2002
Posts: 63
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

Joined: Feb 02, 2002
Posts: 1211

I suggest that you post some relevant code, and somebody may be able to help.
cheers
Rick Gentry
Ranch Hand

Joined: Dec 14, 2002
Posts: 63
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

Joined: Dec 12, 2002
Posts: 580
You need an ItemListener.
D.
Rick Gentry
Ranch Hand

Joined: Dec 14, 2002
Posts: 63
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

Joined: Jul 11, 2001
Posts: 15299
    
    6

Moving to Swing...


GenRocket - Experts at Building Test Data
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Dec 14, 2002
Posts: 63
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
 
subject: JComboBox
 
Similar Threads
Controls to connect database
URLyBird Search Options
drop down menu
JComboBox getSelectedItem() only returning first element
How to restrict data in JTextField?