• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to make a Java ComboBox listener  RSS feed

 
Vena Minks
Greenhorn
Posts: 4
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this code here:



But "obj[0]" is always "obj1".
How to I edit this code so it knows which I selected.

(I don't want the code like https://docs.oracle.com/javase/tutorialJWS/samples/uiswing/ComboBoxDemoProject/ComboBoxDemo.jnlp for example, I want it so it activates a specific line of code when I selected an option and pressed OK).
 
Fred Kleinschmidt
Bartender
Posts: 556
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
obj[0].equals("obj1") will always be true, since obj[0] *is* "obj1".
You need to check whether selection equals "obj1".
 
Vena Minks
Greenhorn
Posts: 4
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I know, that's what I meant.
But my question was what i needed to type to check that if it got selected.
Sorry if I wasn't clear enough in the question itself.
 
Fred Kleinschmidt
Bartender
Posts: 556
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!