Forums Login/signup

JComboBox problem...

+Pie Number of slices to send: Send
hey,
i'm having a problem with getting the first item in the JComboBox() being selected. i have to select another item before i'm able to select the first item and trigger it. i'm using 1.6 :



i never used JComboBox() before, so any help would be appreciated. thanks in advance.

+Pie Number of slices to send: Send
You are facing the problem because of adding ActionListener to JComboBox. Use a ItemListener for the JComboBox. Have a look at java tutorial's JComboBox section for usage and more details. http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html
+Pie Number of slices to send: Send
"VarunKumar",

Please read your private messages regarding an important announcement.

Thank you,

Rob
+Pie Number of slices to send: Send
i added the following; still exhibits the same behavior. also setSelectedIndex() will not work for first item as well. any ideas?

+Pie Number of slices to send: Send
A ItemEvent will be generated only when the selection changes. Since already the first element is being selected setSelectedIndex(0) will not raise an event. You may want to initially set the text for price label or add a first item like "Select a size" to JComboBox and don't set any initial value for price label.
Hope this helps.
+Pie Number of slices to send: Send
try it like this

+Pie Number of slices to send: Send
THANKS mike && varun. that was the solution(s) i needed. i read in another forum that this is the correct behavior as of 1.6. now i can handle it from here. thanks again && take care.

ps. nice use of the ActionListener(), mike

reply
reply
This thread has been viewed 2294 times.
Similar Threads
Java Board Game
problems with this code
Some help.
JList
Date/Time Component Required [URGENT]
More...

All times above are in ranch (not your local) time.
The current ranch time is
Jun 28, 2025 08:29:41.