I needed the Searchable pop up to hide after a given number of miliseconds, so I extended ListSearchable
and wrote a few lines of code which takes care of it. If anyone else needs this functionality, then feel
free to use the below code. I haven't put too much effort in documenting the code, but it is fairly self
explanatory so you shouldn't have too much trouble reading it if you need to make any adjustments.
Usage:
- Code: Select all
JList l = new JList();
ListSearchable lS = new ListSearchableWithTimeOut(l, 350);
The ListSearchableWithTimeOut has two constructors. One which accepts the JList which is to be made
searchable (and which hides the searchable pop up after 350 miliseconds) and one which accepts the JList along
with the delay specified in miliseconds.
- Code: Select all
package com.tracker.utilities.swing.components;
import com.jidesoft.swing.ListSearchable;
import com.jidesoft.swing.event.SearchableEvent;
import com.jidesoft.swing.event.SearchableListener;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JList;
public class ListSearchableWithTimeOut extends ListSearchable {
private final int delay;
private TimerTask task;
private Timer timer;
public ListSearchableWithTimeOut(JList list) {
this(list, 350);
}
public ListSearchableWithTimeOut(JList list, int delay) {
super(list);
this.delay = delay;
initialise();
}
private void initialise() {
timer = new Timer();
addSearchableListener(new SearchableListener() {
public void searchableEventFired(SearchableEvent evt) {
if (task != null) {
task.cancel();
}
task = new HideTask();
timer.schedule(task, delay);
}
});
}
private ListSearchable getListSearchable() {
return this;
}
private class HideTask extends TimerTask {
@Override
public void run() {
getListSearchable().hidePopup();
}
}
}