As the title says... I'd like items in a JList to be "selected" only when they are double clicked. what would be the best way to achieve this kind of behavior ?
You can try something like this:
JList list = new JList(dataModel);
...
MouseListener mouseListener = new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() == 2) // double click?
{
int posicion = list.locationToIndex(e.getPoint());
list.setSelectedIndex(posicion);
}
else if (e.getClickCount() == 1) // single click?
list.clearSelection() ;
}
};
list.addMouseListener(mouseListener);
Tell me if that works... I can't test it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With