I have a JList, which is hooked up to a custom DefaultListModel, and I’d like to change the mouse cursor on some values of the component (depending on the type of item/value). On some items it should be the default cursor, on some other a hand cursor.
I thought I could do this in my custom DefaultListCellRenderer:
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
MyItem item = (MyItem) value;
setText(item.getDisplay());
if (!item.getType().equals("i"))
setCursor(new Cursor(Cursor.HAND_CURSOR)); // <-- doesn’t work
return this;
}
My approach doesn’t work. Any suggestions how to do it in the right way?
You have to update cursor manually when targeting some cell. Here is a small example: