Example usage for javax.swing JSlider addMouseWheelListener

List of usage examples for javax.swing JSlider addMouseWheelListener

Introduction

In this page you can find the example usage for javax.swing JSlider addMouseWheelListener.

Prototype

public synchronized void addMouseWheelListener(MouseWheelListener l) 

Source Link

Document

Adds the specified mouse wheel listener to receive mouse wheel events from this component.

Usage

From source file:Main.java

/**
 * Creates a JSlider built//from w  w  w.j a  va  2s .co m
 * using a {@link DefaultBoundedRangeModel} and 
 * containing a {@link MouseWheelListener} 
 * and some usual default settings
 * 
 * @param model
 * @return the corresponding {@link JSlider}
 */
public static JSlider createJSlider(final BoundedRangeModel model) {
    final JSlider slider = new JSlider(model);
    slider.addMouseWheelListener(new MouseWheelListener() {
        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            slider.setValue(-e.getWheelRotation() * model.getMaximum() / 100 + model.getValue());
        }
    });
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);
    //      slider.setMajorTickSpacing(model.getMaximum()/2);
    //      slider.setMinorTickSpacing(model.getMaximum()/10);
    //      slider.setSnapToTicks(true);
    return slider;
}