Board index » jbuilder » redefining JList behavior

redefining JList behavior


2005-07-16 12:31:34 PM
jbuilder7
Hi,
I have a small problem and I would appreciate any ideas.
I would like to redefine the JList behavior to allow multiple
selection/unselection without having to hold down the "Ctrl"-key.
So, I would like to have the same behavior JList currently has
while holding down the "Ctrl"-key without having to hold it down.
Thanks a lot in advance!
Tony.
 
 

Re:redefining JList behavior

Quote
I would like to redefine the JList behavior to allow multiple
selection/unselection without having to hold down the "Ctrl"-key.
So, I would like to have the same behavior JList currently has
while holding down the "Ctrl"-key without having to hold it down.
Just in case if anyone is interested
class ToggleSelectionModel extends DefaultListSelectionModel
{
boolean gestureStarted = false;
public void setSelectionInterval(int index0, int index1)
{
if (super.getSelectionMode() !=
ListSelectionModel.SINGLE_SELECTION &&
index0 == index1)
{
if (!gestureStarted)
{
if (isSelectedIndex(index0))
{
super.removeSelectionInterval(index0, index1);
}
else
{
super.addSelectionInterval(index0, index1);
}
gestureStarted = true;
}
}
else
{
super.setSelectionInterval(index0, index1);
}
}
public void setValueIsAdjusting(boolean isAdjusting)
{
if (isAdjusting == false)
{
gestureStarted = false;
}
}
}