Java JSlider createJSlider(final BoundedRangeModel model)

Here you can find the source of createJSlider(final BoundedRangeModel model)

Description

Creates a JSlider built using a DefaultBoundedRangeModel and containing a MouseWheelListener and some usual default settings

License

Open Source License

Parameter

Parameter Description
model the model

Return

the corresponding

Declaration

public static JSlider createJSlider(final BoundedRangeModel model) 

Method Source Code

//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;
    }
}

Related

  1. addVerticalMouseListener(final JPanel panel, final JSlider slider)
  2. adjustWithoutNotifyingListeners(JSlider slider, int value)
  3. ajustarValorDeslizador(JSlider sldActual, int valor)
  4. buildIntegerFieldWithSlider(final JSlider matchingSlider)
  5. createLabelField(String preText, String postText, JSlider s)
  6. createSliderPanel(final JSlider slider, String label, int width)
  7. fixWinSliderUI(JSlider s)
  8. makeLabelSliderPanelHorizontal(String text, JSlider slider)