Mojimi
Mojimi

Reputation: 3161

Creating a dynamic search box/table in Java

What I'm trying to achieve is a JTextField with a JTable on the bottom, every time a change occurs on the JTextField (type or delete a character) the JTable would update showing the results from it's list of strings that match what is written on the JTextField, and showing all results if empty.

What I don't know how to do :

  1. How to set the event on the JTextField that triggers everytime its text changes
  2. Making the JTable update its values in an efficient way, without using too much memory

Upvotes: 1

Views: 1646

Answers (1)

trashgod
trashgod

Reputation: 205785

Add a DocumentListener to your JTextField. Update the TableModel belonging to your JTable with matches. The JTable will update itself in response.

Upvotes: 1

Related Questions