• Post Reply Bookmark Topic Watch Topic
  • New Topic

Item Listener Problem

 
Rohan Kalbhor
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I am using a JComboBox on a JFrame.On Frame Load I add a list of items into the JComboBox.When I run the program it runs fine.
But now if I add and Item Listener for the JComboBox the box shows no items.
please help.
this method is called before adding listener

It runs fine

but
---------

after I add this code....the data in JCombobox vanishes
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rohan Kalbhor:
It runs fine

but
---------

after I add this code....the data in JCombobox vanishes


You aren't showing us enough of your code for us to be able to meaningfully comment.

I don't see how the existence (or not) of a method named combotbugnmeItemStateChanged could clear the contents of your combo box. Is this method even called?

Perhaps you are doing something unexpected when instantiating your ItemListener or when registering it with your combo box as a listener, but we can't tell.

this method is called before adding listener


Does it make a difference if you register the listener first? (In general it shouldn't, but trying it might throw some light.)
[ November 13, 2007: Message edited by: Brian Cole ]
 
Rohan Kalbhor
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Brian,
Thankyou for coordination,
I have found out the problem,

instead of the line
String s = (combotbugnme.getSelectedItem()).toString();
if I write
String s = (String)evt.getItem();
---------------
The problem is solved
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!