Preliminary question
How can I build a JTable so that it would be updated when a Google Guava Event is fired (And guarantee it's thread safe)?
The simple way would be to do model.setValueAt(aValue, row, column);
Two problems:
- using the standard data structure of JTableModel, I don't know what row I'm in.
- using the standard data structure of JTableModel, I can't use this data for other components
- this is not thread safe (I think)
I have thought of changing JTableModel to use ConcurrentHashMap but it seems as this is not the intended purpose of extending it. I feel this is a route to strange bugs.
I feel very lost in the middle of all this, if you can just supply a guide of what I should explore first it would help a lot.
A more informed question
The events are not in EVT. To make sure I ran SwingUtilities.isEventDispatchThread()
, the result was false.
What I now think I should do:
@Subscribe
public void handleMessage(DataStructure newInformation) {
// handle the information
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
tableModel.setValueAt(...); // update table1
tableModel2.setValueAt(...); // update table2
}
});
}
In the event I get information that is totally independent of the table. I need a way to know to what row the information relates to.
I can always cycle through the whole vector in the models but I am looking for a solution where I can use a map or array.