Example usage for javax.swing JSlider setMajorTickSpacing

List of usage examples for javax.swing JSlider setMajorTickSpacing

Introduction

In this page you can find the example usage for javax.swing JSlider setMajorTickSpacing.

Prototype

@BeanProperty(visualUpdate = true, description = "Sets the number of values between major tick marks.")
public void setMajorTickSpacing(int n) 

Source Link

Document

This method sets the major tick spacing.

Usage

From source file:House.java

public JSlider setSlider(JPanel panel, int orientation, int minimumValue, int maximumValue, int initValue,
        int majorTickSpacing, int minorTickSpacing) {
    JSlider slider = new JSlider(orientation, minimumValue, maximumValue, initValue);
    slider.setPaintTicks(true);/*from ww w . j av  a2  s  . c o  m*/
    slider.setMajorTickSpacing(majorTickSpacing);
    slider.setMinorTickSpacing(minorTickSpacing);
    slider.setPaintLabels(true);
    slider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            JSlider tempSlider = (JSlider) e.getSource();

            if (tempSlider.equals(sliderTransX)) {
                transX = sliderTransX.getValue() - 150.0;
                canvas.repaint();
            } else if (tempSlider.equals(sliderTransY)) {
                transY = sliderTransY.getValue() - 150.0;
                canvas.repaint();
            } else if (tempSlider.equals(sliderRotateTheta)) {
                rotateTheta = sliderRotateTheta.getValue() * Math.PI / 180;
                canvas.repaint();
            } else if (tempSlider.equals(sliderRotateX)) {
                rotateX = sliderRotateX.getValue();
                canvas.repaint();
            } else if (tempSlider.equals(sliderRotateY)) {
                rotateY = sliderRotateY.getValue();
                canvas.repaint();
            } else if (tempSlider.equals(sliderScaleX)) {
                if (sliderScaleX.getValue() != 0.0) {
                    scaleX = sliderScaleX.getValue() / 100.0;
                    canvas.repaint();
                }
            } else if (tempSlider.equals(sliderScaleY)) {
                if (sliderScaleY.getValue() != 0.0) {
                    scaleY = sliderScaleY.getValue() / 100.0;
                    canvas.repaint();
                }
            }
        }
    });
    panel.add(slider);

    return slider;
}

From source file:MainClass.java

public MainClass() {
    Container cp = new Box(BoxLayout.X_AXIS);
    setContentPane(cp);/*from  w  w w .ja v a 2 s.  co m*/
    JPanel firstPanel = new JPanel();
    propertyComboBox = new JComboBox();
    propertyComboBox.addItem("text");
    propertyComboBox.addItem("font");
    propertyComboBox.addItem("background");
    propertyComboBox.addItem("foreground");
    firstPanel.add(propertyComboBox);
    cp.add(firstPanel);
    cp.add(Box.createGlue());

    tf = new JTextField("Hello");
    tf.setForeground(Color.RED);
    tf.setDragEnabled(true);
    cp.add(tf);

    cp.add(Box.createGlue());

    l = new JLabel("Hello");
    l.setBackground(Color.YELLOW);
    cp.add(l);

    cp.add(Box.createGlue());

    JSlider stryder = new JSlider(SwingConstants.VERTICAL);
    stryder.setMinimum(10);
    stryder.setValue(14);
    stryder.setMaximum(72);
    stryder.setMajorTickSpacing(10);
    stryder.setPaintTicks(true);

    cp.add(stryder);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(500, 300);

    setMyTransferHandlers((String) propertyComboBox.getSelectedItem());

    MouseListener myDragListener = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            JComponent c = (JComponent) e.getSource();
            TransferHandler handler = c.getTransferHandler();
            handler.exportAsDrag(c, e, TransferHandler.COPY);
        }
    };
    l.addMouseListener(myDragListener);

    propertyComboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ce) {
            JComboBox bx = (JComboBox) ce.getSource();
            String prop = (String) bx.getSelectedItem();
            setMyTransferHandlers(prop);
        }
    });

    tf.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            JTextField jtf = (JTextField) evt.getSource();
            String fontName = jtf.getText();
            Font font = new Font(fontName, Font.BOLD, 18);
            tf.setFont(font);
        }
    });

    stryder.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent evt) {
            JSlider sl = (JSlider) evt.getSource();
            Font oldf = tf.getFont();
            Font newf = oldf.deriveFont((float) sl.getValue());
            tf.setFont(newf);
        }
    });
}

From source file:WeatherWizard.java

public void initComponents() {

    setLayout(new BorderLayout());

    JPanel p = new JPanel();
    p.add(new JLabel("Temperature:"));
    JSlider tempSlider = new JSlider(20, 100, 65);
    tempSlider.setMinorTickSpacing(5);/*  w  w w .j  a  va  2  s .  c  om*/
    tempSlider.setMajorTickSpacing(20);
    tempSlider.setPaintTicks(true);
    tempSlider.setPaintLabels(true);
    tempSlider.addChangeListener(this);
    p.add(tempSlider);
    add("North", p);

    painter = new WeatherPainter();
    painter.sun = loadImage("sun");
    painter.cloud = loadImage("cloud");
    painter.rain = loadImage("rain");
    painter.snow = loadImage("snow");
    painter.setTemperature(65);
    p.add("Center", painter);

}

From source file:org.csml.tommo.sugar.modules.heatmap.MixedHeatmapDialog.java

private JSlider createMixParameterSlider() {

    JSlider slider = new JSlider(JSlider.VERTICAL, 0, 100, (int) (mixOperation.getParameter() * 100.0));
    slider.setMajorTickSpacing(10);
    slider.setSnapToTicks(true);//from  ww w .j  ava  2  s .  c o  m
    slider.setPaintTicks(true);
    //         slider.setPaintLabels(true);

    slider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {

            JSlider source = (JSlider) event.getSource();
            if (!source.getValueIsAdjusting()) {
                double param = (double) source.getValue() / (double) 100.0;
                updateMixParameter(param);
            }
        }
    });

    return slider;
}

From source file:AlphaCompositeDemo.java

public AlphaCompositeDemo() {
    super();/* w  ww .  j  a v  a 2  s .c om*/
    Container container = getContentPane();

    canvas = new MyCanvas();
    container.add(canvas);

    rulesBox = new JComboBox(rulesLabels);
    rulesBox.setSelectedIndex(0);
    rulesBox.setAlignmentX(Component.LEFT_ALIGNMENT);
    rulesBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox cb = (JComboBox) e.getSource();
            canvas.compositeRule = rules[cb.getSelectedIndex()];
            canvas.repaint();
        }
    });

    slider.setPaintTicks(true);
    slider.setMajorTickSpacing(25);
    slider.setMinorTickSpacing(25);
    slider.setPaintLabels(true);
    slider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            JSlider slider = (JSlider) e.getSource();
            canvas.alphaValue = (float) slider.getValue() / 100;
            canvas.repaint();
        }
    });

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(1, 3));
    panel.add(rulesBox);
    panel.add(new JLabel("Alpha Adjustment x E-2: ", JLabel.RIGHT));
    panel.add(slider);
    container.add(panel, BorderLayout.SOUTH);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    setSize(500, 300);
    setVisible(true);
}

From source file:Transfer.java

public Transfer() {

    // Establish the GUI
    Container cp = new Box(BoxLayout.X_AXIS);
    setContentPane(cp);/*from w  w  w  .j a v a 2  s.  c o  m*/
    JPanel firstPanel = new JPanel();
    propertyComboBox = new JComboBox();
    propertyComboBox.addItem("text");
    propertyComboBox.addItem("font");
    propertyComboBox.addItem("background");
    propertyComboBox.addItem("foreground");
    firstPanel.add(propertyComboBox);
    cp.add(firstPanel);
    cp.add(Box.createGlue());

    tf = new JTextField("Hello");
    tf.setForeground(Color.RED);
    tf.setDragEnabled(true);
    cp.add(tf);

    cp.add(Box.createGlue());

    l = new JLabel("Hello");
    l.setBackground(Color.YELLOW);
    cp.add(l);

    cp.add(Box.createGlue());

    JSlider stryder = new JSlider(SwingConstants.VERTICAL);
    stryder.setMinimum(10);
    stryder.setValue(14);
    stryder.setMaximum(72);
    stryder.setMajorTickSpacing(10);
    stryder.setPaintTicks(true);

    cp.add(stryder);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(500, 300);

    // Add Listeners and Converters
    setMyTransferHandlers((String) propertyComboBox.getSelectedItem());

    // Mousing in the Label starts a Drag.
    MouseListener myDragListener = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            JComponent c = (JComponent) e.getSource();
            TransferHandler handler = c.getTransferHandler();
            handler.exportAsDrag(c, e, TransferHandler.COPY);
        }
    };
    l.addMouseListener(myDragListener);

    // Selecting in the ComboBox makes that the property that is xfered.
    propertyComboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ce) {
            JComboBox bx = (JComboBox) ce.getSource();
            String prop = (String) bx.getSelectedItem();
            setMyTransferHandlers(prop);
        }
    });

    // Typing a word and pressing enter in the TextField tries
    // to set that as the font name.
    tf.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            JTextField jtf = (JTextField) evt.getSource();
            String fontName = jtf.getText();
            Font font = new Font(fontName, Font.BOLD, 18);
            tf.setFont(font);
        }
    });

    // Setting the Slider sets that font into the textfield.
    stryder.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent evt) {
            JSlider sl = (JSlider) evt.getSource();
            Font oldf = tf.getFont();
            Font newf = oldf.deriveFont((float) sl.getValue());
            tf.setFont(newf);
        }
    });

}

From source file:components.SliderDemo2.java

public SliderDemo2() {
    super(new BorderLayout());

    delay = 1000 / FPS_INIT;//from   w  ww.j  ava  2s. c o m

    //Create the slider.
    JSlider framesPerSecond = new JSlider(JSlider.VERTICAL, FPS_MIN, FPS_MAX, FPS_INIT);
    framesPerSecond.addChangeListener(this);
    framesPerSecond.setMajorTickSpacing(10);
    framesPerSecond.setPaintTicks(true);

    //Create the label table.
    Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();
    //PENDING: could use images, but we don't have any good ones.
    labelTable.put(new Integer(0), new JLabel("Stop"));
    //new JLabel(createImageIcon("images/stop.gif")) );
    labelTable.put(new Integer(FPS_MAX / 10), new JLabel("Slow"));
    //new JLabel(createImageIcon("images/slow.gif")) );
    labelTable.put(new Integer(FPS_MAX), new JLabel("Fast"));
    //new JLabel(createImageIcon("images/fast.gif")) );
    framesPerSecond.setLabelTable(labelTable);

    framesPerSecond.setPaintLabels(true);
    framesPerSecond.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));

    //Create the label that displays the animation.
    picture = new JLabel();
    picture.setHorizontalAlignment(JLabel.CENTER);
    picture.setAlignmentX(Component.CENTER_ALIGNMENT);
    picture.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLoweredBevelBorder(),
            BorderFactory.createEmptyBorder(10, 10, 10, 10)));
    updatePicture(0); //display first frame

    //Put everything together.
    add(framesPerSecond, BorderLayout.LINE_START);
    add(picture, BorderLayout.CENTER);
    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    //Set up a timer that calls this object's action handler.
    timer = new Timer(delay, this);
    timer.setInitialDelay(delay * 7); //We pause animation twice per cycle
                                      //by restarting the timer
    timer.setCoalesce(true);
}

From source file:components.SliderDemo.java

public SliderDemo() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));

    delay = 1000 / FPS_INIT;/*  w  w w  . jav a2 s .c  o  m*/

    //Create the label.
    JLabel sliderLabel = new JLabel("Frames Per Second", JLabel.CENTER);
    sliderLabel.setAlignmentX(Component.CENTER_ALIGNMENT);

    //Create the slider.
    JSlider framesPerSecond = new JSlider(JSlider.HORIZONTAL, FPS_MIN, FPS_MAX, FPS_INIT);

    framesPerSecond.addChangeListener(this);

    //Turn on labels at major tick marks.

    framesPerSecond.setMajorTickSpacing(10);
    framesPerSecond.setMinorTickSpacing(1);
    framesPerSecond.setPaintTicks(true);
    framesPerSecond.setPaintLabels(true);
    framesPerSecond.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
    Font font = new Font("Serif", Font.ITALIC, 15);
    framesPerSecond.setFont(font);

    //Create the label that displays the animation.
    picture = new JLabel();
    picture.setHorizontalAlignment(JLabel.CENTER);
    picture.setAlignmentX(Component.CENTER_ALIGNMENT);
    picture.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLoweredBevelBorder(),
            BorderFactory.createEmptyBorder(10, 10, 10, 10)));
    updatePicture(0); //display first frame

    //Put everything together.
    add(sliderLabel);
    add(framesPerSecond);
    add(picture);
    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    //Set up a timer that calls this object's action handler.
    timer = new Timer(delay, this);
    timer.setInitialDelay(delay * 7); //We pause animation twice per cycle
                                      //by restarting the timer
    timer.setCoalesce(true);
}

From source file:SliderTest.java

public SliderTestFrame() {
    setTitle("SliderTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    sliderPanel = new JPanel();
    sliderPanel.setLayout(new FlowLayout(FlowLayout.LEFT));

    // common listener for all sliders
    listener = new ChangeListener() {
        public void stateChanged(ChangeEvent event) {
            // update text field when the slider value changes
            JSlider source = (JSlider) event.getSource();
            textField.setText("" + source.getValue());
        }/*from ww w .  j a  v  a2  s .  com*/
    };

    // add a plain slider

    JSlider slider = new JSlider();
    addSlider(slider, "Plain");

    // add a slider with major and minor ticks

    slider = new JSlider();
    slider.setPaintTicks(true);
    slider.setMajorTickSpacing(20);
    slider.setMinorTickSpacing(5);
    addSlider(slider, "Ticks");

    // add a slider that snaps to ticks

    slider = new JSlider();
    slider.setPaintTicks(true);
    slider.setSnapToTicks(true);
    slider.setMajorTickSpacing(20);
    slider.setMinorTickSpacing(5);
    addSlider(slider, "Snap to ticks");

    // add a slider with no track

    slider = new JSlider();
    slider.setPaintTicks(true);
    slider.setMajorTickSpacing(20);
    slider.setMinorTickSpacing(5);
    slider.setPaintTrack(false);
    addSlider(slider, "No track");

    // add an inverted slider

    slider = new JSlider();
    slider.setPaintTicks(true);
    slider.setMajorTickSpacing(20);
    slider.setMinorTickSpacing(5);
    slider.setInverted(true);
    addSlider(slider, "Inverted");

    // add a slider with numeric labels

    slider = new JSlider();
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);
    slider.setMajorTickSpacing(20);
    slider.setMinorTickSpacing(5);
    addSlider(slider, "Labels");

    // add a slider with alphabetic labels

    slider = new JSlider();
    slider.setPaintLabels(true);
    slider.setPaintTicks(true);
    slider.setMajorTickSpacing(20);
    slider.setMinorTickSpacing(5);

    Dictionary<Integer, Component> labelTable = new Hashtable<Integer, Component>();
    labelTable.put(0, new JLabel("A"));
    labelTable.put(20, new JLabel("B"));
    labelTable.put(40, new JLabel("C"));
    labelTable.put(60, new JLabel("D"));
    labelTable.put(80, new JLabel("E"));
    labelTable.put(100, new JLabel("F"));

    slider.setLabelTable(labelTable);
    addSlider(slider, "Custom labels");

    // add a slider with icon labels

    slider = new JSlider();
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);
    slider.setSnapToTicks(true);
    slider.setMajorTickSpacing(20);
    slider.setMinorTickSpacing(20);

    labelTable = new Hashtable<Integer, Component>();

    // add card images

    labelTable.put(0, new JLabel(new ImageIcon("nine.gif")));
    labelTable.put(20, new JLabel(new ImageIcon("ten.gif")));
    labelTable.put(40, new JLabel(new ImageIcon("jack.gif")));
    labelTable.put(60, new JLabel(new ImageIcon("queen.gif")));
    labelTable.put(80, new JLabel(new ImageIcon("king.gif")));
    labelTable.put(100, new JLabel(new ImageIcon("ace.gif")));

    slider.setLabelTable(labelTable);
    addSlider(slider, "Icon labels");

    // add the text field that displays the slider value

    textField = new JTextField();
    add(sliderPanel, BorderLayout.CENTER);
    add(textField, BorderLayout.SOUTH);
}

From source file:jku.ss09.mir.lastfmecho.bo.visualization.MirArtistNetworkGraphVisualizer.java

public boolean init() {

    if (artistList.size() > similarityMatrix.length) {
        System.out.println(/*from  ww w .  ja va2s  . c  om*/
                "Error in MirArtistNetworkGraphVisualizer - The similaritymatrix is smaller than number of artists ");
        return false;
    }

    graph = getGraph(SIMILARITY_DEFAULT / 100.0);
    setVisualizationRenderer();

    // create a frome to hold the graph
    final JFrame frame = new JFrame();
    Container content = frame.getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final ModalGraphMouse gm = new DefaultModalGraphMouse<Integer, Number>();
    vv.setGraphMouse(gm);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JSlider slider = new JSlider(JSlider.HORIZONTAL, SIMILARITY_MIN, SIMILARITY_MAX, SIMILARITY_DEFAULT);
    slider.setMajorTickSpacing(10);
    slider.setPaintTicks(true);

    final JLabel sliderLabel = new JLabel("0.87");

    final MirArtistNetworkGraphVisualizer thisPointer = this;

    slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent arg0) {
            JSlider source = (JSlider) arg0.getSource();
            if (!source.getValueIsAdjusting()) {
                System.out.println(source.getValue() / 100.0);

                Graph testG = getGraph(source.getValue() / 100.0);
                sliderLabel.setText(Double.toString(source.getValue() / 100.0));
                thisPointer.vv.setGraphLayout(new FRLayout<Integer, Number>(testG));
                //thisPointer.setVisualizationRenderer();
                thisPointer.vv.validate();
                thisPointer.vv.repaint();

            }
        }

    });

    JPanel controls = new JPanel();
    controls.add(plus);
    controls.add(minus);
    controls.add(((DefaultModalGraphMouse<Integer, Number>) gm).getModeComboBox());
    controls.add(new JLabel("Similarity Limit: "));
    controls.add(sliderLabel);
    controls.add(slider);
    content.add(controls, BorderLayout.SOUTH);

    frame.pack();
    frame.setVisible(true);

    return true;
}