Example usage for javax.swing JSlider setPaintTicks

List of usage examples for javax.swing JSlider setPaintTicks

Introduction

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

Prototype

@BeanProperty(visualUpdate = true, description = "If true tick marks are painted on the slider.")
public void setPaintTicks(boolean b) 

Source Link

Document

Determines whether tick marks are painted on the slider.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // Create a horizontal slider that moves left-to-right
    JSlider slider = new JSlider();

    slider.setPaintTicks(true);

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("Icon Slider");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Icon icon = new ImageIcon("logo.gif");
    UIDefaults defaults = UIManager.getDefaults();
    defaults.put("Slider.horizontalThumbIcon", icon);
    JSlider aJSlider = new JSlider();
    aJSlider.setPaintTicks(true);
    frame.add(aJSlider, BorderLayout.NORTH);
    frame.setSize(300, 200);//from   w ww. j a v a 2 s.  c  o m
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    JFrame f = new JFrame("JSlider Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JSlider slider = new JSlider();
    slider.setMinorTickSpacing(5);/*from w  w w. ja  v a2 s. c o m*/
    slider.setMajorTickSpacing(10);
    slider.setPaintTicks(true);
    slider.setSnapToTicks(true);
    slider.setPaintTrack(false);
    slider.setPaintLabels(true);
    f.add(slider, BorderLayout.CENTER);
    f.setSize(300, 100);
    f.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();

    oneJSlider.setValue(27);/*from w  w w .j a va  2 s .c o m*/

    int value = oneJSlider.getValue();
    System.out.println(value);

    oneJSlider.setPaintTicks(true);

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

From source file:TickSliders.java

public static void main(String args[]) {
    JFrame f = new JFrame("Tick Slider");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // No Ticks//from   w  w  w  . j  av a  2 s.c  o  m
    JSlider jSliderOne = new JSlider();
    // Major Tick 25 - Minor 5
    JSlider jSliderTwo = new JSlider();
    jSliderTwo.setMinorTickSpacing(5);
    jSliderTwo.setMajorTickSpacing(25);
    jSliderTwo.setPaintTicks(true);
    jSliderTwo.setSnapToTicks(true);
    // Major Tick 25 - Minor 6
    JSlider jSliderThree = new JSlider(JSlider.VERTICAL);
    jSliderThree.setMinorTickSpacing(6);
    jSliderThree.setMajorTickSpacing(25);
    jSliderThree.setPaintTicks(true);
    JSlider jSliderFour = new JSlider(JSlider.VERTICAL);
    // Major Tick 25 - Minor 1
    jSliderFour.setMinorTickSpacing(1);
    jSliderFour.setMajorTickSpacing(25);
    jSliderFour.setPaintTicks(true);

    Container c = f.getContentPane();
    c.add(jSliderOne, BorderLayout.NORTH);
    c.add(jSliderTwo, BorderLayout.SOUTH);
    c.add(jSliderThree, BorderLayout.WEST);
    c.add(jSliderFour, BorderLayout.EAST);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:TickSliders.java

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

    JSlider jSliderOne = new JSlider();

    // Major Tick 25 - Minor 5
    jSliderOne.setMinorTickSpacing(5);/*from   w  w  w  .ja v a 2  s.com*/
    jSliderOne.setMajorTickSpacing(25);
    jSliderOne.setPaintTicks(true);
    jSliderOne.setSnapToTicks(true);

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

From source file:SampleSliders.java

public static void main(String args[]) {
    String title = (args.length == 0 ? "Sample Slider" : args[0]);
    JFrame f = new JFrame(title);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSlider js1 = new JSlider();
    js1.putClientProperty("JSlider.isFilled", Boolean.TRUE);
    JSlider js2 = new JSlider();
    js2.setMajorTickSpacing(25);/* ww w .j av  a 2  s . c  o  m*/
    js2.setPaintTicks(true);
    js2.setSnapToTicks(true);
    JSlider js3 = new JSlider(JSlider.VERTICAL);
    js3.setPaintTrack(false);
    js3.setMinorTickSpacing(5);
    js3.setMajorTickSpacing(10);
    js3.setPaintTicks(true);
    js3.setPaintLabels(true);
    js3.setSnapToTicks(true);
    JSlider js4 = new JSlider(JSlider.VERTICAL);
    Hashtable table = new Hashtable();
    table.put(new Integer(0), new JLabel(new DiamondIcon(Color.red)));
    table.put(new Integer(10), new JLabel("Ten"));
    table.put(new Integer(25), new JLabel("Twenty-Five"));
    table.put(new Integer(34), new JLabel("Thirty-Four"));
    table.put(new Integer(52), new JLabel("Fifty-Two"));
    table.put(new Integer(70), new JLabel("Seventy"));
    table.put(new Integer(82), new JLabel("Eighty-Two"));
    table.put(new Integer(100), new JLabel(new DiamondIcon(Color.black)));
    js4.setLabelTable(table);
    js4.setPaintLabels(true);
    js4.setSnapToTicks(true);
    Container c = f.getContentPane();
    c.add(js1, BorderLayout.NORTH);
    c.add(js2, BorderLayout.SOUTH);
    c.add(js3, BorderLayout.WEST);
    c.add(js4, BorderLayout.EAST);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:Main.java

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

    JPanel main = new JPanel(new GridLayout(2, 1));
    JPanel scrollBarPanel = new JPanel();
    final JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL, 0, 48, 0, 255);
    int height = scrollBar.getPreferredSize().height;
    scrollBar.setPreferredSize(new Dimension(175, height));
    scrollBarPanel.add(scrollBar);/*from   w ww  .j ava2s.c  o m*/
    main.add(scrollBarPanel);

    JPanel sliderPanel = new JPanel();
    final JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 255, 128);
    slider.setMajorTickSpacing(48);
    slider.setMinorTickSpacing(16);
    slider.setPaintTicks(true);
    sliderPanel.add(slider);
    main.add(sliderPanel);

    frame.add(main, BorderLayout.CENTER);

    scrollBar.addAdjustmentListener(new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent e) {
            System.out.println("JScrollBar's current value = " + scrollBar.getValue());
        }
    });

    slider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            System.out.println("JSlider's current value = " + slider.getValue());
        }
    });

    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    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 w w  w  .ja v  a  2  s  .c o m

    oneJSlider.setPaintTicks(true);

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

From source file:JSliderOnJOptionPane.java

static JSlider getSlider(final JOptionPane optionPane) {
    JSlider slider = new JSlider();
    slider.setMajorTickSpacing(10);/*w ww .  ja v a 2 s .c  o m*/
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);
    ChangeListener changeListener = new ChangeListener() {
        public void stateChanged(ChangeEvent changeEvent) {
            JSlider theSlider = (JSlider) changeEvent.getSource();
            if (!theSlider.getValueIsAdjusting()) {
                optionPane.setInputValue(new Integer(theSlider.getValue()));
            }
        }
    };
    slider.addChangeListener(changeListener);
    return slider;
}