• Post Reply Bookmark Topic Watch Topic
  • New Topic

GetSelectedItem isn't getting selected item  RSS feed

 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the piece of code below - I was wanting to select an item in a comboBox and display it in a text field but all it's doing at the minute is retrieving the first item in the comboBox and placing that in the txt field



That should work shouldn't it?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that code executed every time you the selection in the combo is changed, or only once before the user interacts with the GUI?

Have you discovered the Oracle tutorials? http://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html

And since this is about Swing, I'm moving the thread.
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is how mine is like the Oracle website have it


I don't think it's set up right I think I have it set up right as I think I've more than likely got it set up once before the user interacts with the gui as I the first environment in the comboBox displays in the text field from the moment the comboBox is actually oepened...
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also see comments
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that okay?



The comboBox basically sits in a window with a text field underneath for the id from the comboBox to pass into if selected.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alice Hampton wrote:Is that okay?


1. Can I compile and run it to see the problem?
2. Does it NOT contain stuff that is irrelevant to the problem?

Did you go through the linked page about the SSCCE?
Did you go through the combo box tutorial I linked to find what listener should be used to detect a change of selection?
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I have used an action listener but that's now causing different problems -i'll take that code out,there's not really much use it being there
 
Rob Camick
Ranch Hand
Posts: 2756
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its annoying that I spend time answering your other question: http://www.coderanch.com/t/640650/GUI/java/items-comboBox-prefix-file

Keep the discussion in one place so everybody knows what has already been suggested!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!