7 Years
Discussion Span
Last Post by Abdel_eid

Entering in a JTextField? I'd probably try addint a KeyListener. When it fires a keyTyped KeyEvent, get the current text and off you go.


desktop application means that the software runs on a computer (ordinary software on any computer) not on a server(web site)


Have you ever added an ActionListener to one of your buttons. So whenever you click a button the actionPeformed method will be executed.

It is the same thing. Add a KeyListener to the text field.
Use the addKeyListener method of the JTextField class. You need to implement the KeyListener listener interface. You don't need to write code in all of the methods. Just write for only the keyReleased. When you enter text at the field, every time you release a key from the keyboard that method is executed. So all you have to do is take the text from the field

JTextField nameField = new JTextField();

public void keyReleased(KeyEvent e) {
   String name = nameField.getText();


If you try to enter the name: JACK, the above method will print:
> J
> JA

Every time you release a "key" that method is executed. So if you have a method that returns the names that begin with the argument, take the text from the field call that method and show the results. That will be executed every time you keep entering characters in the field.

The hard part is after you have the list with names how to make it look like "google". For that you need to do a little search, on the net. Because I don't have the time to do some searching and point you to right direction.


ok thanks you man i will try it then return to you back to inform you about the results

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.