Results 1 to 5 of 5
- 01-03-2011, 02:14 PM #1
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
Which combobox event to use to fill a textbox
Hello guys,
I have a combobox with values: 2,3,4,5
When i select value 3, from the list i get out of the combobox, i want to fill the textbox with my name.
When i use codeComboBoxActionPerformed event or the MouseClicked event, nothing happens.
My code is correct to fill the textbox:
searchNameTextField.setText("André");
I hope you can tell me what event to use.
Thanks
Kind regards,
André
- 01-03-2011, 03:52 PM #2
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
With the ItemStateChanged event handler, i have found it.
But now i always get the first record in the database.
I want to select item four and then i want to have the fourth item of my recordset surname in my textfield.
Java Code:private void codeComboBoxItemStateChanged(java.awt.event.ItemEvent evt) { String name = searchNameTextField.getText(); aStudent = Student.getStudent(name); searchNameTextField.setText(aStudent.getSurname()); }
- 01-03-2011, 04:14 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
I don't understand what you're doing here. Your JComboBox contains the Strings "2", "3", "4" and "5". When a selection changes you can get back one of those Strings. One way or another you should have a mapping from those Strings to names (also Strings), i.e. "4" --> "Andre". Given this mapping you can set the text of another JComponent.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-03-2011, 04:28 PM #4
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
Sorry, i hope to be more clear.
1 have one textfield called surname
1 have one combobox who gets, with method: "getCode()", 4 records from a database
2
3
4
5
In the same table we have the surname
2 Borgeld
3 Eastwoord
4 Bakker
5 Bush
I can search the surname with a button and a like query via the method "getSurname".
I fill the combobox with an Array via a while loop.
When i click the combobox and pick record 4 the textfield stays empty.
My purpose is then when i click the combobox and i choose 2 that the textfield displays "Borgeld"
When i choose 3 the textfield displays "Eastwoord".
- 01-03-2011, 05:18 PM #5
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
Similar Threads
-
How to set value to a TextBox
By kishan in forum JavaServer Faces (JSF)Replies: 3Last Post: 06-29-2010, 02:46 PM -
Access textbox value in javabean
By newto in forum New To JavaReplies: 6Last Post: 05-13-2010, 03:42 PM -
creating itemstate event handler of array of combobox at runtime.
By pophils in forum AWT / SwingReplies: 0Last Post: 03-22-2010, 06:45 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks