Example usage for javax.swing JSlider setLabelTable

List of usage examples for javax.swing JSlider setLabelTable

Introduction

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

Prototype

@BeanProperty(hidden = true, visualUpdate = true, description = "Specifies what labels will be drawn for any given value.")
@SuppressWarnings("rawtypes")
public void setLabelTable(Dictionary labels) 

Source Link

Document

Used to specify what label will be drawn at any given value.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JSlider slider = new JSlider();

    Dictionary table = slider.getLabelTable();

    ImageIcon icon = new ImageIcon("icon.gif");
    JLabel label = new JLabel(icon);

    // Set at desired positions
    table.put(new Integer(slider.getMinimum()), label);
    table.put(new Integer(slider.getMaximum()), label);

    // Force the slider to use the new labels
    slider.setLabelTable(table);

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    String title = (args.length == 0 ? "Sample Slider" : args[0]);
    JFrame frame = new JFrame(title);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JSlider js4 = new JSlider(JSlider.VERTICAL);
    Hashtable<Integer, JLabel> table = new Hashtable<Integer, JLabel>();
    table.put(0, new JLabel("O"));
    table.put(10, new JLabel("Ten"));
    table.put(25, new JLabel("Twenty-Five"));
    table.put(34, new JLabel("Thirty-Four"));
    table.put(52, new JLabel("Fifty-Two"));
    table.put(70, new JLabel("Seventy"));
    table.put(82, new JLabel("Eighty-Two"));
    table.put(100, new JLabel("100"));
    js4.setLabelTable(table);
    js4.setPaintLabels(true);//from w  w w .j a v a  2  s  . com
    js4.setSnapToTicks(true);
    frame.add(js4, BorderLayout.EAST);
    frame.setSize(300, 200);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Tick Slider");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSlider jSliderOne = new JSlider();

    jSliderOne.setPaintLabels(true);/*from www  . j ava 2  s  .  co  m*/

    Hashtable<Integer, JLabel> table = new Hashtable<Integer, JLabel>();
    table.put(0, new JLabel(new ImageIcon("yourFile.gif")));
    table.put(10, new JLabel("Ten"));
    table.put(25, new JLabel("Twenty-Five"));
    table.put(34, new JLabel("Thirty-Four"));
    table.put(52, new JLabel("Fifty-Two"));
    table.put(70, new JLabel("Seventy"));
    table.put(82, new JLabel("Eighty-Two"));
    jSliderOne.setLabelTable(table);

    frame.add(jSliderOne, BorderLayout.NORTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:SampleSliders.java

public static void main(String args[]) {
    String title = (args.length == 0 ? "Sample Slider" : args[0]);
    JFrame f = new JFrame(title);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSlider js1 = new JSlider();
    js1.putClientProperty("JSlider.isFilled", Boolean.TRUE);
    JSlider js2 = new JSlider();
    js2.setMajorTickSpacing(25);/*from  w  w  w  .  j  av  a  2s .co m*/
    js2.setPaintTicks(true);
    js2.setSnapToTicks(true);
    JSlider js3 = new JSlider(JSlider.VERTICAL);
    js3.setPaintTrack(false);
    js3.setMinorTickSpacing(5);
    js3.setMajorTickSpacing(10);
    js3.setPaintTicks(true);
    js3.setPaintLabels(true);
    js3.setSnapToTicks(true);
    JSlider js4 = new JSlider(JSlider.VERTICAL);
    Hashtable table = new Hashtable();
    table.put(new Integer(0), new JLabel(new DiamondIcon(Color.red)));
    table.put(new Integer(10), new JLabel("Ten"));
    table.put(new Integer(25), new JLabel("Twenty-Five"));
    table.put(new Integer(34), new JLabel("Thirty-Four"));
    table.put(new Integer(52), new JLabel("Fifty-Two"));
    table.put(new Integer(70), new JLabel("Seventy"));
    table.put(new Integer(82), new JLabel("Eighty-Two"));
    table.put(new Integer(100), new JLabel(new DiamondIcon(Color.black)));
    js4.setLabelTable(table);
    js4.setPaintLabels(true);
    js4.setSnapToTicks(true);
    Container c = f.getContentPane();
    c.add(js1, BorderLayout.NORTH);
    c.add(js2, BorderLayout.SOUTH);
    c.add(js3, BorderLayout.WEST);
    c.add(js4, BorderLayout.EAST);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:Main.java

public static void setTickMarkers(JSlider slider) {
    final int min = slider.getMinimum();
    final int max = slider.getMaximum();
    final int delta = max - min;

    if (delta > 0) {
        final int sliderSize;
        if (slider.getOrientation() == SwingConstants.HORIZONTAL)
            sliderSize = slider.getPreferredSize().width;
        else// w  w  w.  j a v a2 s.c om
            sliderSize = slider.getPreferredSize().height;

        // adjust ticks space on slider
        final int majTick = findBestMajTickSpace(sliderSize, delta);

        slider.setMinorTickSpacing(Math.max(1, majTick / 5));
        slider.setMajorTickSpacing(majTick);
        slider.setLabelTable(slider.createStandardLabels(slider.getMajorTickSpacing(), majTick));
    }
}

From source file:Presentation.MainWindow.java

private void addSlider() {
    JSlider sliderTemp = new JSlider(12, 26, 26);
    sliderTemp.setLabelTable(sliderTemp.createStandardLabels(14));
    sliderTemp.setMinorTickSpacing(1);//from   w w w .  ja va2  s  .c  om
    sliderTemp.setPaintLabels(true);
    sliderTemp.setPaintTicks(true);
    this.tSlider = sliderTemp;
    Label labelConsigne = new Label("Temprature de consigne : " + tSlider.getValue() + " C");
    //Label labelOutdoorTemp = new Label(Singleton.getInstance().getAcquisition().getOutdoorTemp());
    this.tLabel = labelConsigne;
    mPanel.add(labelConsigne);
    mPanel.add(sliderTemp);
}

From source file:Main.java

public Main() {
    setLayout(new BorderLayout());
    JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 50, 25);

    slider.setMinorTickSpacing(2);/*from  w w w .j  a  v a  2  s .  c om*/
    slider.setMajorTickSpacing(10);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);

    slider.setInverted(false);

    // We'll just use the standard numeric labels for now...
    slider.setLabelTable(slider.createStandardLabels(10));

    add(slider, BorderLayout.CENTER);
}

From source file:Main.java

public Main() {
    setLayout(new BorderLayout());
    JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 50, 25);

    slider.setMinorTickSpacing(2);//  w w w .ja v  a  2  s.  c  om
    slider.setMajorTickSpacing(10);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);

    slider.setOrientation(JSlider.VERTICAL);
    slider.setInverted(true);

    // We'll just use the standard numeric labels for now...
    slider.setLabelTable(slider.createStandardLabels(10));

    add(slider, BorderLayout.CENTER);
}

From source file:Main.java

public Main() {
    setLayout(new BorderLayout());
    JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 50, 25);

    slider.setMinorTickSpacing(2);/*from  ww w  . java2 s. c  o  m*/
    slider.setMajorTickSpacing(10);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);

    slider.setOrientation(JSlider.VERTICAL);
    slider.setInverted(false);

    // We'll just use the standard numeric labels for now...
    slider.setLabelTable(slider.createStandardLabels(10));

    add(slider, BorderLayout.CENTER);
}

From source file:JXTransformer.java

private JPanel createDemoPanel() {
        JPanel buttonPanel = new JPanel(new GridLayout(3, 2));
        TitledBorder titledBorder = BorderFactory.createTitledBorder("Try three sliders below !");
        Font titleFont = titledBorder.getTitleFont();
        titledBorder.setTitleFont(titleFont.deriveFont(titleFont.getSize2D() + 10));
        titledBorder.setTitleJustification(TitledBorder.CENTER);
        buttonPanel.setBorder(titledBorder);
        JButton b = new JButton("JButton");
        b.setPreferredSize(new Dimension(100, 50));
        buttonPanel.add(createTransformer(b));

        Vector<String> v = new Vector<String>();
        v.add("One");
        v.add("Two");
        v.add("Three");
        JList list = new JList(v);
        buttonPanel.add(createTransformer(list));

        buttonPanel.add(createTransformer(new JCheckBox("JCheckBox")));

        JSlider slider = new JSlider(0, 100);
        slider.setLabelTable(slider.createStandardLabels(25, 0));
        slider.setPaintLabels(true);/*w w w  .  j a v a 2 s  .c  om*/
        slider.setPaintTicks(true);
        slider.setMajorTickSpacing(10);
        buttonPanel.add(createTransformer(slider));

        buttonPanel.add(createTransformer(new JRadioButton("JRadioButton")));
        final JLabel label = new JLabel("JLabel");
        label.addMouseListener(new MouseAdapter() {
            public void mouseEntered(MouseEvent e) {
                Font font = label.getFont();
                label.setFont(font.deriveFont(font.getSize2D() + 10));
            }

            public void mouseExited(MouseEvent e) {
                Font font = label.getFont();
                label.setFont(font.deriveFont(font.getSize2D() - 10));
            }
        });
        buttonPanel.add(createTransformer(label));

        return buttonPanel;
    }