Here you can find the source of createJSlider(final BoundedRangeModel model)
Parameter | Description |
---|---|
model | the model |
public static JSlider createJSlider(final BoundedRangeModel model)
//package com.java2s; /*// w w w . j a va 2 s . com * Copyright 1997-2013 Fabien Michel, Olivier Gutknecht, Jacques Ferber * * This file is part of MaDKit. * * MaDKit is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MaDKit is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MaDKit. If not, see <http://www.gnu.org/licenses/>. */ import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import javax.swing.BoundedRangeModel; import javax.swing.JSlider; public class Main { /** * Creates a JSlider built using a {@link DefaultBoundedRangeModel} and * containing a {@link MouseWheelListener} and some usual default settings * * @param model the 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; } }