Example usage for javax.swing JSlider getModel

List of usage examples for javax.swing JSlider getModel

Introduction

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

Prototype

public BoundedRangeModel getModel() 

Source Link

Document

Returns the BoundedRangeModel that handles the slider's three fundamental properties: minimum, maximum, value.

Usage

From source file:BoundedRangeModelInJSlider.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Tick Slider");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSlider oneJSlider = new JSlider();

    System.out.println(oneJSlider.getModel().getMaximum());

    frame.add(oneJSlider, BorderLayout.NORTH);

    frame.setSize(300, 200);//from w  ww.  j  a v a2s  . com
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSlider oneJSlider = new JSlider();

    int newValue = 2;
    int newExtent = 10;
    int newMin = 0;
    int newMax = 10;
    oneJSlider.getModel().setRangeProperties(newValue, newExtent, newMin, newMax, true);
    int value = oneJSlider.getValue();
    System.out.println(value);//from ww  w.j a  va2  s  .  com

    oneJSlider.setPaintTicks(true);

    frame.add(oneJSlider, BorderLayout.NORTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JSlider slider = new JSlider();
    BoundedRangeModel model = slider.getModel();
    model.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            BoundedRangeModel m = (BoundedRangeModel) e.getSource();
            System.out.println("Slider position changed to " + m.getValue());
        }/*  w ww.  j a  va2s.  co  m*/
    });
    getContentPane().add(slider);
    pack();
}

From source file:test.uk.co.modularaudio.util.swing.lwtc.TestShowLWTCSliderComparison.java

public void go(final int orientation) throws Exception {

    final JSlider testSwingJSlider = new JSlider(orientation);
    testSwingJSlider.setOpaque(false);//w  ww.  j av a2 s. c o  m

    final BoundedRangeModel defaultSwingSliderModel = testSwingJSlider.getModel();
    log.debug("Default swing slider model is " + defaultSwingSliderModel.toString());

    final JFrame f = new JFrame();

    f.getContentPane().setBackground(Color.decode("#3a5555"));

    final MigLayoutStringHelper msg = new MigLayoutStringHelper();
    //      msg.addLayoutConstraint( "debug" );
    msg.addLayoutConstraint("fill");
    msg.addLayoutConstraint("insets 0");
    msg.addLayoutConstraint("gap 0");
    if (orientation == SwingConstants.VERTICAL) {
        msg.addColumnConstraint("[][grow][grow][]");
        msg.addRowConstraint("[][grow][]");
    } else {
        msg.addColumnConstraint("[][grow][]");
        msg.addRowConstraint("[][grow][grow][]");
    }
    f.setLayout(msg.createMigLayout());

    f.add(new JLabel("o"), "center");
    f.add(new JLabel("o"), "center");
    if (orientation == SwingConstants.VERTICAL) {
        f.add(new JLabel("o"), "center");
    }
    f.add(new JLabel("o"), "center,wrap");

    f.add(new JLabel("o"), "center");
    if (orientation == SwingConstants.VERTICAL) {
        f.add(verticalKnobContainer, "center, grow");
        f.add(testSwingJSlider, "center, grow");
    } else {
        f.add(horizontalKnobContainer, "center, grow");
    }
    f.add(new JLabel("o"), "center,wrap");

    if (orientation == SwingConstants.HORIZONTAL) {
        f.add(new JLabel("o"), "center");
        f.add(testSwingJSlider, "center, grow");
        f.add(new JLabel("o"), "center, wrap");
    }

    f.add(new JLabel("o"), "center");
    if (orientation == SwingConstants.VERTICAL) {
        f.add(new JLabel("o"), "center");
    }
    f.add(new JLabel("o"), "center");
    f.add(new JLabel("o"), "center");

    f.pack();

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            f.setVisible(true);
        }
    });
}