e794. 创建JSlider组件

// Create a horizontal slider with min=0, max=100, value=50
    JSlider slider = new JSlider();
    
    // Create a horizontal slider with custom min and max; value is set to the middle
    int minimum = -255;
    int maximum = 256;
    slider = new JSlider(minimum, maximum);
    
    // Create a horizontal slider with custom min, max, and value
    int initValue = 0;
    slider = new JSlider(minimum, maximum, initValue);
    
    // Create a vertical slider with min=0, max=100, value=50
    slider = new JSlider(JSlider.VERTICAL);
    
    // Create a vertical slider with custom min, max, and value
    slider = new JSlider(JSlider.VERTICAL, minimum, maximum, initValue);

In addition to allowing the user to drag the slider, some look and feels allow the user page the slider by a fixed amount. This amount is called the extent.

    // Set an extent
    int extent = 10;
    slider.setExtent(extent);

For most look and feels, the slider appears as a knob on a track. In this case, it is possible to hide the track:

    slider.setPaintTrack(false);
Related Examples
原文地址:https://www.cnblogs.com/borter/p/9596224.html