Guest User

Untitled

a guest
Jan 22nd, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  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.
Add Comment
Please, Sign In to add comment