Hey all.

I intend to write a custom ListSelectionListener (or at least, that is what I think will solve my problem) that only allows zero to two selected values (not intervals). Obviously I googled what I'm writing as my title (so I'm writing this title to help people looking for this later on) beforehand - and it gave me only one relevant result from stackoverflow - but the problem was unsolved.

When 2 values are already selected, deselect the value that was last selected (all I need here, I think, are two int variables (one for the first selected value, one for the last selected value, where -1 is nothing selected) that I change everytime a selection change is fired).
- And in case of dragging the mouse around to select a value, don't deselect when hitting a selected value, until valueIsAdjusting() returns false.

Well, I have no idea where to start so if anyone out there just have a pinpoint to what I should do (write a class that extends ListSelectionListener, or whatever) and maybe a single line of description of why that's the optimal way of doing it - since I have no experience other than using the default three options.

And just to give you an idea of what I might understand: I started learning Java from August this year - and it's my first programming language.

Whenever someone is delightful enough to give me some directions I'll write an SSCCE so it will become easier to help me further.

Thanks in advance!