I'm using glazedlists for auto-completion but i want to ask something in this point. I have an arraylist for friendlist. People can be added to friendlist or can be removed from friendlist by clicking add or remove button. Data of friendlist is written to friend.txt and is read from friend.txt ,by using Gson and Json. When user add a person to the list or remove a person from the list the selected person is removed from or added to friend.txt.
...
Object[] elements = new Object[holdSizeValue];
for( int i = 0 ; i < holdSizeValue ; i++ ){
elements[i] = sendFriendNameFromList(i);
}
searchBox = new JComboBox<Object>();
final EventList<Object> eventList = GlazedLists.eventList(Arrays.asList(elements));
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
AutoCompleteSupport.install(searchBox, eventList);
}
});
...
As you might understand from the code, i used glazedlist for search operation.I want to update elements[]. How can i update ? When i call the method ,which includes the code above , from controller of add or remove button i am getting an exception which is about invokeAndWait.
The major advantage of the EventList is that once it's initialised you simply add objects to it and everything that is observing that data, e.g., the ComboBox will magically update thanks to all the plumbing GlazedLists provides.
So, move the
EventList
to be an instance variable:Perform the AutoCompleteSupport once, after the
searchBox
has been created and set up.Then, when you need to add items call
eventList.addAll(...)
. Don't reinstantiate that list, nor reinstanstiate the searchBox each time you want to do an update. Add/remove with the event list and the rest will follow automatically.