How do I refresh the view when I finish entering a key in a filter in Eclipse?
I have a view with a table and a search box above the table. I am currently updating the view every time a key is issued. This causes some lag.
Code:
searchText.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(final KeyEvent ke) {
filter.setSearchText(searchText.getText());
viewer.refresh();
}
});
How can I update the view only when the user stops writing?
+3
source to share
1 answer
You can achieve this with a threshold and a Timer :
final Timer timer = new Timer(threshold, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
filter.setSearchText(searchText.getText());
viewer.refresh();
}
});
timer.setRepeat(false);
searchText.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(final KeyEvent ke) {
timer.restart();
}
});
+2
source to share