Create Inverted JSliders in Java

Description

The following code shows how to create Inverted JSliders.

Example


/*from  w w  w  .j  ava  2 s  .c  o m*/

import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JFrame;
import javax.swing.JSlider;

public class Main {
  public static void main(String args[]) {
    JFrame f = new JFrame("Inverted Sliders");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSlider js1 = new JSlider();
    js1.setMajorTickSpacing(10);
    js1.setPaintTicks(true);
    js1.setPaintLabels(true);
    JSlider js2 = new JSlider();
    js2.setInverted(true);
    js2.setMajorTickSpacing(10);
    js2.setPaintTicks(true);
    js2.setPaintLabels(true);
    JSlider js3 = new JSlider(JSlider.VERTICAL);
    js3.setPaintTrack(false);
    js3.setMajorTickSpacing(10);
    js3.setPaintTicks(true);
    js3.setPaintLabels(true);
    JSlider js4 = new JSlider(JSlider.VERTICAL);
    js4.setInverted(true);
    js4.setMajorTickSpacing(10);
    js4.setPaintTicks(true);
    js4.setPaintLabels(true);
    Container c = f.getContentPane();
    c.add(js1, BorderLayout.NORTH);
    c.add(js2, BorderLayout.SOUTH);
    c.add(js3, BorderLayout.EAST);
    c.add(js4, BorderLayout.WEST);
    f.setSize(300, 250);
    f.setVisible(true);
  }
}

The code above generates the following result.

Create Inverted JSliders in Java




















Home »
  Java Tutorial »
    Swing »




Action
Border
Color Chooser
Drag and Drop
Event
Font Chooser
JButton
JCheckBox
JComboBox
JDialog
JEditorPane
JFileChooser
JFormattedText
JFrame
JLabel
JList
JOptionPane
JPasswordField
JProgressBar
JRadioButton
JScrollBar
JScrollPane
JSeparator
JSlider
JSpinner
JSplitPane
JTabbedPane
JTable
JTextArea
JTextField
JTextPane
JToggleButton
JToolTip
JTree
Layout
Menu
Timer