Java Swing BoundedRangeModel handle change event
import java.awt.BorderLayout; import javax.swing.BoundedRangeModel; import javax.swing.JFrame; import javax.swing.JSlider; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public class Main extends JFrame { public Main() { JSlider slider = new JSlider(); BoundedRangeModel model = slider.getModel(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().add(slider, BorderLayout.CENTER); model.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { System.out.println("Value: " + model.getValue()); }/*from w ww .ja v a 2 s . c o m*/ }); pack(); setVisible(true); } public static void main(String arg[]) { new Main(); } }