Example usage for javax.swing JSlider JSlider

List of usage examples for javax.swing JSlider JSlider

Introduction

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

Prototype

public JSlider() 

Source Link

Document

Creates a horizontal slider with the range 0 to 100 and an initial value of 50.

Usage

From source file:CurvedExample.java

public CurvedExample() {
    super(true);/*from   w  w  w  . j a  va  2  s.com*/

    JSlider mySlider = new JSlider();
    mySlider.setMajorTickSpacing(20);
    mySlider.setMinorTickSpacing(10);
    mySlider.setPaintTicks(true);
    mySlider.setPaintLabels(true);

    CurvedBorder border = new CurvedBorder(10, Color.darkGray);
    mySlider.setBorder(border);

    add(mySlider);
}

From source file:MainClass.java

public MainClass() {
    Box box = new Box(BoxLayout.Y_AXIS);
    box.add(new JButton("Test button"));
    box.add(new JSlider());
    box.add(new JTextField("Text field with some text", 20));
    box.add(new JButton("Another, bigger button"));

    getContentPane().add(box);/* w w  w .  ja v  a  2 s  .  c o m*/
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
}

From source file:Main.java

public Main() {
    Container content = getContentPane();
    content.setBackground(Color.white);

    JSlider slider1 = new JSlider();
    slider1.setBorder(BorderFactory.createTitledBorder("JSlider without Tick Marks"));

    content.add(slider1, BorderLayout.NORTH);

    JSlider slider2 = new JSlider();
    slider2.setBorder(BorderFactory.createTitledBorder("JSlider with Tick Marks"));

    slider2.setMajorTickSpacing(20);//ww w.j av a  2s  . c o m
    slider2.setMinorTickSpacing(5);
    slider2.setPaintTicks(true);
    content.add(slider2, BorderLayout.CENTER);

    JSlider slider3 = new JSlider();
    slider3.setBorder(BorderFactory.createTitledBorder("JSlider with Tick Marks & Labels"));

    slider3.setMajorTickSpacing(20);
    slider3.setMinorTickSpacing(5);
    slider3.setPaintTicks(true);
    slider3.setPaintLabels(true);
    content.add(slider3, BorderLayout.SOUTH);

    setSize(300, 300);
    setVisible(true);
}

From source file:EventTracerTest.java

public EventTracerFrame() {
    setTitle("EventTracerTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    // add a slider and a button
    add(new JSlider(), BorderLayout.NORTH);
    add(new JButton("Test"), BorderLayout.SOUTH);

    // trap all events of components inside the frame
    EventTracer tracer = new EventTracer();
    tracer.add(this);
}

From source file:org.jfree.chart.demo.bottom_slider.java

/**
 * Create the panel.//from   ww  w.  j  av  a 2s  . c  o m
 */

public bottom_slider(Color color, ArrayList<JFreeChart> chart, final Graphic graph, int num) {
    setBounds(5, 380, 740, 100);
    setLayout(null);
    charts = chart;
    plot = charts.get(num).getXYPlot();

    table = new JTable(
            new Object[][] { { "Slider", "X", "Y", "X1-X2", "Y1-Y2" }, { "Slider1", null, null, null, null },
                    { "Slider2", null, null, null, null } },
            new String[] { "Slider", "X", "Y", "X1-X2", "Y1-Y2" });
    setBackground(color);
    table.setBounds(255, 22, 485, 48);
    add(table);

    slider_2 = new JSlider();
    slider_2.setBounds(5, 22, 250, 20);
    slider_2.setBackground(color);
    slider_2.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            try {
                int value = slider_2.getValue();

                ValueAxis domainAxis = plot.getDomainAxis();
                Range range = domainAxis.getRange();

                X1 = domainAxis.getLowerBound() + (value / 100.0) * range.getLength();

                int i = 0;
                for (; i < graph.mas_x.size(); i++) {
                    //   System.out.println("X"+  Arrays.toString(graph.mas_x.toArray()));
                    if (graph.mas_x.get(i).doubleValue() <= X1) {
                    } else {
                        break;
                    }
                }
                Y1 = graph.mas_y.get(i).doubleValue();
            } catch (Exception e1) {
                if (e.toString() == "java.lang.IndexOutOfBoundsException")
                    Y1 = graph.mas_y.get(graph.mas_y.size() - 1).doubleValue();
            }
            plot.removeDomainMarker(distanceTiers2);
            distanceTiers2 = new ValueMarker(X1);
            distanceTiers2.setPaint(Color.BLACK);
            plot.addDomainMarker(distanceTiers2);

            table.setValueAt("" + new BigDecimal(X1).setScale(3, RoundingMode.UP).doubleValue(), 1, 1);
            table.setValueAt("" + new BigDecimal(Y1).setScale(3, RoundingMode.UP).doubleValue(), 1, 2);
            table.setValueAt("" + new BigDecimal(X2).setScale(3, RoundingMode.UP).doubleValue(), 2, 1);
            table.setValueAt("" + new BigDecimal(Y2).setScale(3, RoundingMode.UP).doubleValue(), 2, 2);

            table.setValueAt("" + new BigDecimal(Math.abs(X2 - X1)).setScale(3, RoundingMode.UP).doubleValue(),
                    2, 3);
            table.setValueAt("" + new BigDecimal(Math.abs(X2 - X1)).setScale(3, RoundingMode.UP).doubleValue(),
                    1, 3);
            table.setValueAt("" + new BigDecimal(Math.abs(Y2 - Y1)).setScale(3, RoundingMode.UP).doubleValue(),
                    2, 4);
            table.setValueAt("" + new BigDecimal(Math.abs(Y2 - Y1)).setScale(3, RoundingMode.UP).doubleValue(),
                    1, 4);
        }

    });
    add(slider_2);

    slider_3 = new JSlider();
    slider_3.setBounds(5, 55, 250, 20);
    slider_3.setBackground(color);
    slider_3.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            try {
                int value = slider_3.getValue();

                ValueAxis domainAxis = plot.getDomainAxis();
                Range range = domainAxis.getRange();

                X2 = domainAxis.getLowerBound() + (value / 100.0) * range.getLength();

                plot.removeDomainMarker(distanceTiers1);
                distanceTiers1 = new ValueMarker(X2);
                distanceTiers1.setPaint(Color.BLACK);

                plot.addDomainMarker(distanceTiers1);
                int i = 0;
                for (; i < graph.mas_x.size(); i++) {

                    if (graph.mas_x.get(i).doubleValue() <= X2) {
                    } else {
                        break;
                    }

                }

                Y2 = graph.mas_y.get(i).doubleValue();

            } catch (Exception e1) {
                if (e.toString() == "java.lang.IndexOutOfBoundsException")
                    Y1 = graph.mas_y.get(graph.mas_y.size() - 1).doubleValue();
            }
            table.setValueAt("" + new BigDecimal(X1).setScale(3, RoundingMode.UP).doubleValue(), 1, 1);
            table.setValueAt("" + new BigDecimal(Y1).setScale(3, RoundingMode.UP).doubleValue(), 1, 2);
            table.setValueAt("" + new BigDecimal(X2).setScale(3, RoundingMode.UP).doubleValue(), 2, 1);
            table.setValueAt("" + new BigDecimal(Y2).setScale(3, RoundingMode.UP).doubleValue(), 2, 2);

            table.setValueAt("" + new BigDecimal(Math.abs(X2 - X1)).setScale(3, RoundingMode.UP).doubleValue(),
                    2, 3);
            table.setValueAt("" + new BigDecimal(Math.abs(X2 - X1)).setScale(3, RoundingMode.UP).doubleValue(),
                    1, 3);
            table.setValueAt("" + new BigDecimal(Math.abs(Y2 - Y1)).setScale(3, RoundingMode.UP).doubleValue(),
                    2, 4);
            table.setValueAt("" + new BigDecimal(Math.abs(Y2 - Y1)).setScale(3, RoundingMode.UP).doubleValue(),
                    1, 4);
        }
    });
    add(slider_3);
}

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   www. j a v  a2 s  .c  o m
    };

    // 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:biomine.bmvis2.pipeline.EdgeGoodnessHider.java

public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) {
    double maxEdge = 0;
    for (VisualEdge e : graph.getAllEdges()) {
        maxEdge = Math.max(maxEdge, e.getGoodness());
    }/*from w ww .j a  v  a  2s. c  o m*/

    final int scale = 100;
    final JSlider limitSlider = new JSlider();
    limitSlider.setMinimum(0);
    limitSlider.setMaximum(scale);
    limitSlider.setValue((int) (limit * scale));
    final JTextField limitText = new JTextField();
    limitText.setEditable(false);
    limitText.setText("" + limit);

    limitSlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent arg0) {
            limit = limitSlider.getValue() / (double) scale;
            limitText.setText("" + limit);
            v.settingsChanged(false);
        }
    });

    JPanel ret = new JPanel();
    GridBagLayout bag = new GridBagLayout();
    ret.setLayout(bag);
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.fill = c.HORIZONTAL;
    ret.add(limitSlider, c);
    c.gridy++;
    ret.add(limitText, c);
    return ret;
}

From source file:lu.lippmann.cdb.datasetview.tabs.WeightedMapOfDecisionTreesTabView.java

/**
 * Constructor.//from w  w  w.  java2s  . com
 */
public WeightedMapOfDecisionTreesTabView(final EventPublisher eventPublisher,
        final CommandDispatcher commandDispatcher, final ApplicationContext applicationContext) {
    super();

    this.applicationContext = applicationContext;
    this.commandDispatcher = commandDispatcher;
    this.eventPublisher = eventPublisher;

    final double defaultValueConfidenceFactor = DecisionTreeHelper.HIGH_CONFIDENCE_FACTOR;
    this.dtFactory = new J48DecisionTreeFactory(defaultValueConfidenceFactor, false);
    this.panel = new JXPanel();
    this.panel.setLayout(new BorderLayout());

    this.slider = new JSlider();
    this.slider.setBorder(new TitledBorder("Confidence factor"));
    this.slider.setOpaque(false);
    this.slider.setMaximum((int) (defaultValueConfidenceFactor * 100));
    this.slider.setValue((int) (defaultValueConfidenceFactor * 100));
    this.slider.setMinimum(1);
    this.slider.setMinorTickSpacing(1);
    this.slider.setMajorTickSpacing(10);
    this.slider.setPaintTicks(true);
    this.slider.setPaintLabels(true);
    this.panel.add(this.slider, BorderLayout.SOUTH);

    this.attrSelectionCombo = new JComboBox();
    this.attrSelectionCombo.setBorder(new TitledBorder("Attribute used to split"));

    final JXPanel cmdPanel = new JXPanel();
    cmdPanel.setLayout(new BorderLayout());
    cmdPanel.add(this.attrSelectionCombo, BorderLayout.CENTER);
    this.withWeightCheckBox = new JCheckBox("Weighted");
    this.withWeightCheckBox.setBorder(new TitledBorder("With weight"));
    cmdPanel.add(this.withWeightCheckBox, BorderLayout.EAST);
    this.panel.add(cmdPanel, BorderLayout.NORTH);
}

From source file:MessagePopup.java

public static JSlider getSlider(final JOptionPane optionPane) {
    JSlider slider = new JSlider();
    slider.setMajorTickSpacing(10);//from   w  ww  . ja  v a  2  s  . c om
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);
    ChangeListener changeListener = new ChangeListener() {
        public void stateChanged(ChangeEvent changeEvent) {
            JSlider theSlider = (JSlider) changeEvent.getSource();
            if (!theSlider.getValueIsAdjusting()) {
                optionPane.setInputValue(new Integer(theSlider.getValue()));
            }
        }
    };
    slider.addChangeListener(changeListener);
    return slider;
}

From source file:org.nees.rpi.vis.ui.ProfilePlotFrame.java

private void initSliderArea() {
    JPanel sliderArea = new JPanel();
    sliderArea.setOpaque(false);/* w  w  w  .j  av  a  2 s  .  c  o m*/
    sliderArea.setLayout(new BorderLayout());
    sliderArea.setBorder(BorderFactory.createTitledBorder("Time"));
    contentPane.add(sliderArea, BorderLayout.SOUTH);

    timeSlider = new JSlider();
    timeSlider.setOpaque(false);
    timeSlider.addChangeListener(new ProfileSliderChangeListener());
    timeSlider.addMouseListener(new ProfileSliderMouseListener());

    timeLabel = new JLabel();
    styleTimeLabel();

    JPanel buttonArea = new JPanel();
    buttonArea.setOpaque(false);
    BoxLayout buttonAreaLayout = new BoxLayout(buttonArea, BoxLayout.Y_AXIS);
    buttonArea.setLayout(buttonAreaLayout);

    playButton = new VisLinkButton("Play", getClass().getResource("/images/profile-plot/plotplay.png"));
    playButton.setToolTipText("Display a timed incremental sequence of the profiles");
    playButton.addActionListener(new PlayProfilesMovie());

    pauseButton = new VisLinkButton("Pause", getClass().getResource("/images/profile-plot/plotpause.png"));
    pauseButton.setToolTipText("Pause the playback of the profiles sequence");
    pauseButton.addActionListener(new PauseProfilesMovie());
    pauseButton.setVisible(false);

    nextButton = new VisLinkButton("Forward", getClass().getResource("/images/profile-plot/plotnext.png"));
    nextButton.setToolTipText("Plot the profile for the next time increment");
    nextButton.addActionListener(new MoveToNextTimeIncrement());

    previousButton = new VisLinkButton("Back", getClass().getResource("/images/profile-plot/plotprevious.png"));
    previousButton.setToolTipText("Plot the profile for the previous time increment");
    previousButton.addActionListener(new MoveToPreviousTimeIncrement());

    buttonArea.add(playButton);
    buttonArea.add(pauseButton);
    buttonArea.add(nextButton);
    buttonArea.add(previousButton);

    sliderArea.add(timeSlider, BorderLayout.CENTER);
    sliderArea.add(timeLabel, BorderLayout.SOUTH);
    sliderArea.add(buttonArea, BorderLayout.WEST);
}