Creating a dynamic search box/table in Java

1.6k views Asked by At

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
1

There are 1 answers

1
trashgod On

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