Created
October 27, 2011 22:15
-
-
Save spalladino/1321067 to your computer and use it in GitHub Desktop.
EventThreadListModel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EventThreadListModel extends DefaultListModel { | |
private static final long serialVersionUID = -4389671662282607290L; | |
private void invokeOnEventThread(Runnable r) { | |
try { | |
if (!SwingUtilities.isEventDispatchThread()) { | |
SwingUtilities.invokeAndWait(r); | |
} else { | |
r.run(); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
throw new RuntimeException(e); | |
} | |
} | |
@Override | |
protected void fireContentsChanged(final Object source, final int index0, final int index1) { | |
invokeOnEventThread(new Runnable() { | |
public void run() { | |
EventThreadListModel.super.fireContentsChanged(source, index0, index1); | |
} | |
}); | |
} | |
@Override | |
protected void fireIntervalAdded(final Object source, final int index0, final int index1) { | |
invokeOnEventThread(new Runnable() { | |
public void run() { | |
EventThreadListModel.super.fireIntervalAdded(source, index0, index1); | |
} | |
}); | |
} | |
@Override | |
protected void fireIntervalRemoved(final Object source, final int index0, final int index1) { | |
invokeOnEventThread(new Runnable() { | |
public void run() { | |
EventThreadListModel.super.fireIntervalRemoved(source, index0, index1); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment