Results 1 to 5 of 5
  1. #1
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default 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é

  2. #2
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    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());
        }

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,774
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by aborgeld View Post
    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());
        }
    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,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    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".

  5. #5
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    Hello Josh,

    I solved it, i'm getting the selectedItem with my textbox from the combobox.


    It works fine now.

    Thanks looking at my problem.

    King regards,

    André

Similar Threads

  1. How to set value to a TextBox
    By kishan in forum JavaServer Faces (JSF)
    Replies: 3
    Last Post: 06-29-2010, 03:46 PM
  2. Access textbox value in javabean
    By newto in forum New To Java
    Replies: 6
    Last Post: 05-13-2010, 04:42 PM
  3. Replies: 0
    Last Post: 03-22-2010, 07:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •