Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.*;
- import javax.swing.*;
- public class SliderTest {
- public static void main(String args[]) {
- JFrame frame = new JFrame();
- frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent we) {
- System.exit(0);
- }
- });
- frame.setSize(300, 250);
- JSlider slider = new JSlider(0, 100, 0);
- slider.setMajorTickSpacing(10);
- slider.setMinorTickSpacing(1);
- slider.setPaintLabels(true);
- slider.setPaintTicks(true);
- slider.setMajorTickSpacing(25);
- slider.setMinorTickSpacing(5);
- frame.add(slider);
- frame.pack();
- frame.setVisible(true);
- }
- }
- public void setMajorTickSpacing(int n) {
- int oldValue = majorTickSpacing;
- majorTickSpacing = n;
- if ( labelTable == null && getMajorTickSpacing() > 0 && getPaintLabels() ) {
- setLabelTable( createStandardLabels( getMajorTickSpacing() ) );
- }
- firePropertyChange("majorTickSpacing", oldValue, majorTickSpacing);
- if (majorTickSpacing != oldValue && getPaintTicks()) {
- repaint();
- }
- }
- * This method will also set up a label table for you.
- * If there is not already a label table, and the major tick spacing is
- * {@code > 0}, and {@code getPaintLabels} returns
- * {@code true}, a standard label table will be generated (by calling
- * {@code createStandardLabels}) with labels at the major tick marks.
Add Comment
Please, Sign In to add comment