0

Here's some example code, using Groovy's swingbuilder to create the code for the valueChanged event of a JList:

    mainList.valueChanged = { event ->
        if (event.isAdjusting) {
            index = mainList.selectedIndex
            otherList.clearSelection()
            otherIndex = otherList.selectedIndex
        } else {
            mainListSelected = true
            clearJList(otherList)
        }
    }

I have two JList's, and this function kind of controls which list is allowed to be selected via the mainListSelected variable. We also then have to change int eindex we want to use from the selection based on whether or not it's an index from mainList or otherList

I've read about event.isAdjusting, and it only fires twice like this on a mouse click event. With this knowledge, you would think I would just move everything out of there, but I need certain things to happen differently if the mouse is what causes the event as opposed to using arrows. However, with this code, using arrow key navigation prevents the index from ever changing.

Ajv2324
  • 422
  • 8
  • 24
  • 3
    `but I need certain things to happen differently if the mouse is what causes the event as opposed to using arrows` - why? The standard UI that application use is that a mouse click or using up/down on the keyboard will select the item. A double click or using the Enter key will then invoke a default Action on the selected object. A user should be able to either use the mouse or the keyboard to do processing. – camickr Jul 25 '17 at 20:56
  • See also [What is the XY problem?](http://meta.stackexchange.com/q/66377) – Andrew Thompson Jul 26 '17 at 03:03

0 Answers0