SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.event.*;
  2. import javax.swing.*;
  3.  
  4. public class SliderTest {
  5.     public static void main(String args[]) {
  6.         JFrame frame = new JFrame();
  7.         frame.addWindowListener(new WindowAdapter() {
  8.             public void windowClosing(WindowEvent we) {
  9.                 System.exit(0);
  10.             }
  11.         });
  12.         frame.setSize(300, 250);
  13.  
  14.         JSlider slider = new JSlider(0, 100, 0);
  15.         slider.setMajorTickSpacing(10);
  16.         slider.setMinorTickSpacing(1);
  17.         slider.setPaintLabels(true);
  18.         slider.setPaintTicks(true);
  19.  
  20.         slider.setMajorTickSpacing(25);
  21.         slider.setMinorTickSpacing(5);
  22.  
  23.         frame.add(slider);
  24.         frame.pack();
  25.         frame.setVisible(true);
  26.     }
  27. }
  28.    
  29. public void setMajorTickSpacing(int n) {
  30.     int oldValue = majorTickSpacing;
  31.     majorTickSpacing = n;
  32.     if ( labelTable == null && getMajorTickSpacing() > 0 && getPaintLabels() ) {
  33.         setLabelTable( createStandardLabels( getMajorTickSpacing() ) );
  34.     }
  35.     firePropertyChange("majorTickSpacing", oldValue, majorTickSpacing);
  36.     if (majorTickSpacing != oldValue && getPaintTicks()) {
  37.         repaint();
  38.     }
  39. }
  40.    
  41. * This method will also set up a label table for you.
  42.  * If there is not already a label table, and the major tick spacing is
  43.  * {@code > 0}, and {@code getPaintLabels} returns
  44.  * {@code true}, a standard label table will be generated (by calling
  45.  * {@code createStandardLabels}) with labels at the major tick marks.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top