I was wondering how to modify a JList
so that clicking any values would not do anything. I have looked at other questions but none have helped.
Make JList Values Unselectable [duplicate]
I solved it by using the following class:
class DisabledItemSelectionModel extends DefaultListSelectionModel {
@Override
public void setSelectionInterval(int index0, int index1) {
super.setSelectionInterval(-1, -1);
}
}
I instantiated the class here:
console.setSelectionModel(new DisabledItemSelectionModel());
For me, setting selection mode (!) to
SINGLE_SELECTION
does not prevent it. But overriding public void addSelectionInterval(int index0, int index1)
with the same super.setSelectionInterval(-1, -1);
does. –
Tisiphone Assuming your objects in your JList are clickable items, just do setEnabled(false)
on all the objects you want to disable
@HovercraftFullOfEels I am writing Strings to the JList, so there's no way I could disable Strings. –
Adversative
© 2022 - 2024 — McMap. All rights reserved.
SINGLE_SELECTION
. – Belenbelesprit