JComboBox

I'm currently writing a program for my Java class, and I need to be able to retrieve a selected item from a JComboBox.

//accept new data

newFirst = firstField.getText();

newLast = lastField.getText();

newCity = cityField.getText();

newStateBox = StateCombo.getItemText();

How would you do that? With the other variables, you can just put getText(), but I don't know what you use for JComboBoxes. Any help?

[451 byte] By [kmetzgerr33a] at [2007-11-27 4:00:25]
# 1

http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html

Follow the bouncing link for information about JComboBoxes

In short though you want to get the selected item.

JComboBox.getSelectedItem().getText() which should be close but might not be exact. Read the information in the link it will tell you exactly.

PS.

puckstopper31a at 2007-7-12 9:05:02 > top of Java-index,Java Essentials,Java Programming...
# 2
I'll look at it and see what I can do, thx
kmetzgerr33a at 2007-7-12 9:05:02 > top of Java-index,Java Essentials,Java Programming...
# 3
getSelectedIndex() works better in my opinion because it returns the position selected and as long as you know what that is it makes if trees easier
popupmana at 2007-7-12 9:05:02 > top of Java-index,Java Essentials,Java Programming...