JComboBox Selection

How can i select the text in JComboBox ?Help me guys
[66 byte] By [MCA134a] at [2007-11-26 21:32:22]
# 1

Not really sure what you are asking. A combo box is not designed to select text. It contains a finite number of items. You select an item, not the partial text of the item.

Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html]How to Use Combo Boxes[/url].

camickra at 2007-7-10 3:13:10 > top of Java-index,Desktop,Core GUI APIs...
# 2
Sir,if i type incorrect phone number in the JComboBox field, i want to(in code) show the given phone number is incorrect and select (cursor selection) the that incorrect phone number in that field, not clear the field.byBalasundaram.L
MCA134a at 2007-7-10 3:13:10 > top of Java-index,Desktop,Core GUI APIs...
# 3

If you have your combo box has strings as items (which i assume, because you said you want to select text...) you simply write an ActionListener like you would do for a JButton. in actionPerformed you cast the source to JComboBox and getSelectedIdem() then returns your String (cast to string)...like this:

public void actionPerformed(ActionEvent aE) {

JComboBox combo = (JComboBox)eA.getSource();

String YourString = (String)combo .getSelectedItem();

//pass YourString to method or something

}

jEti182a at 2007-7-10 3:13:11 > top of Java-index,Desktop,Core GUI APIs...
# 4

In that case you should think about using an inputVerifier

http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/InputVerifier.html

which has a method that gets fired when someone changes the combo...

in that method you can cast the source to JComboBox and then use setSelectedIdem(obj) to select the item of your choice...

JComboBox api:

http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JComboBox.html

jEti182a at 2007-7-10 3:13:11 > top of Java-index,Desktop,Core GUI APIs...
# 5
Thanks jEti182byBalasundaram.L
MCA134a at 2007-7-10 3:13:11 > top of Java-index,Desktop,Core GUI APIs...