JSlider

The JSlider control allows the user to select any int type value within a range defined by a minimum value and a maximum value. The widely used from of the constructer of JSlider class is as follows:

JSlider(JSlider.VERTICAL);

This constructor creates a vertical slider.

Program

00



 
 
 

Program Source

import javax.swing.JFrame;
import javax.swing.JSlider;
import javax.swing.JLabel;
import java.awt.FlowLayout;

class JSliderTest extends JFrame {

    JSliderTest()
    {
        setTitle("JSlider");
        setLayout(new FlowLayout());
        setJSlider();
        setSize(700, 250);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    private void setJSlider()
    {
        JSlider slider1 = new JSlider();
        add(new JLabel("slider1"));
        add(slider1);
        
        JSlider slider2 = new JSlider(JSlider.VERTICAL);
        add(new JLabel("slider2"));
        add(slider2);
    }
}

public class Javaapp {
   
    public static void main(String[] args) {
        
        JSliderTest js = new JSliderTest();
    }
}

Leave a Comment