java - JSlider Event Firing twice -


i have simple jslider attached changelisterner. here's code:

jslider slider = new jslider(); slider.setminortickspacing(2); slider.setmajortickspacing(20); slider.setpaintlabels(true); slider.setpaintticks(true); slider.setsnaptoticks(true); slider.setorientation(swingconstants.vertical); contentpane.add(slider, borderlayout.center);  slider.addchangelistener(new sliderlistener());  class sliderlistener implements changelistener {     public void statechanged(changeevent e) {         jslider source = (jslider)e.getsource();         if (!source.getvalueisadjusting()) {             system.out.println("boo");         }         } } 

as can see, code isn't doing much, want make sure event firing once, , hence event print console within eclipse.

but above code printing "boo" twice each time change slider. i'm guessing has got mouse release on slider, whatever is, want fire event once, , hence print word once.

how can achieve that?

thanks

are listener not added twice ? following sscce works expected on machine (os x, jdk7)

import javax.swing.jframe; import javax.swing.jslider; import javax.swing.windowconstants; import javax.swing.event.changeevent; import javax.swing.event.changelistener; import java.awt.eventqueue;  public class slidertest {   public static void main( string[] args ) {     eventqueue.invokelater( new runnable() {       @override       public void run() {         jframe frame = new jframe(  );         final jslider slider = new jslider( 0, 100 );         frame.add( slider );         slider.addchangelistener( new changelistener() {           @override           public void statechanged( changeevent e ) {             if ( !( slider.getvalueisadjusting() ) ){               system.out.println( "slidertest.statechanged" );             }           }         } );         frame.pack();         frame.setvisible( true );         frame.setdefaultcloseoperation( windowconstants.exit_on_close );       }     } );   } } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -