I am doing custom rendering in a JList. My custom ListCellRenderer uses a static String so that it can test the value of a particular variable against the previous occurance of that variable.
private static String lastUsername = "";
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
User user = (User)value;
if (lastUsername == user.getUsername()) {
// Do something
} else {
// Do something else
lastUsername = user.getUsername();
}
Now, that works fine when the program first loads but if I then scroll the list it causes problems as the lastUsername variable is still set to the last username it encountered when in fact it should be an empty string. Basically lastUsername needs to be reset to an empty string before or after all the cells have been rendered. Does anyone know if there is an JList post/pre AllCellsRendered event/hook that I can override to achieve this?