Groovy SwingBuilder ToggleButton StateChange

129 views Asked by At

Is there anyway to avoid the stateChange event being fired more than one time when the toggleButton is clicked? Or am I using the wrong event handler? It gets called 5 times for every toggle.

#!/usr/bin/env groovy

import groovy.swing.SwingBuilder

import static javax.swing.JFrame.EXIT_ON_CLOSE

def swing = new SwingBuilder()
swing.edt {
    lookAndFeel 'nimbus'
    frame(title                : "Throttle",
          pack                 : true,
          show                 : true,
          defaultCloseOperation: EXIT_ON_CLOSE,
          id                   : "frame" ) {
        boxLayout()
        toggleButton(text: 'fl',
                     selected       : false,
                     rolloverEnabled: false,
                     toolTipText    : 'f1',
                     stateChanged   : { e ->
                         println e.source
                     })
    }
}

swing.doLater { frame.size = [128, 320] }
1

There are 1 answers

0
TX T On

I switched to from stateChanged to actionPerformed then it worked as what I expected. Not sure why I used stateChanged in the first place!