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(int min, int max, int value) 

Source Link

Document

Creates a horizontal slider using the specified min, max and value.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int initValue = 0;
    int minimum = 10;
    int maximum = 100;
    JSlider slider = new JSlider(minimum, maximum, initValue);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    final JSlider slider = new JSlider(0, 150, 0);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    slider.setPreferredSize(new Dimension(150, 30));
    slider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent event) {
            int value = slider.getValue();
            if (value == 0) {
                System.out.println("0");
            } else if (value > 0 && value <= 30) {
                System.out.println("value > 0 && value <= 30");
            } else if (value > 30 && value < 80) {
                System.out.println("value > 30 && value < 80");
            } else {
                System.out.println("max");
            }/*from  w  w  w . j  av  a2 s .c om*/
        }
    });
    f.add(slider);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:api3.transform.PlotWave.java

public PlotWave() {
    frame = new JFrame();
    panel = new JPanel();
    panel.setLayout(new BorderLayout());
    slider = new JSlider(0, 200, SLIDER_DEFAULT_VALUE);
    lastValue = SLIDER_DEFAULT_VALUE;//ww w  . j a  v  a2s. c om
}

From source file:ch.zhaw.ias.dito.ui.util.SingleHistogramPanel.java

public SingleHistogramPanel(Matrix m) {
    super(new BorderLayout());
    this.m = m;//  w  ww. jav a  2s  .  co  m
    this.chart = createChart();
    this.chartPanel = new ChartPanel(this.chart);

    Border border = BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createEtchedBorder());
    this.chartPanel.setBorder(border);
    add(this.chartPanel, BorderLayout.CENTER);

    JPanel dashboard = new JPanel(new BorderLayout());
    dashboard.setBorder(BorderFactory.createEmptyBorder(0, 4, 4, 4));

    this.spinner = new JSpinner(new SpinnerNumberModel(0, 0, m.getColCount() - 1, 1));
    spinner.addChangeListener(this);
    this.slider = new JSlider(0, m.getColCount() - 1, 0);
    slider.setPaintLabels(true);

    slider.setMajorTickSpacing(Math.max(50, 10 * Math.round(m.getColCount() / 100)));
    slider.setPaintTicks(true);
    this.slider.addChangeListener(this);

    FormLayout layout = new FormLayout("fill:0:g, max(20dlu; pref)", "top:pref");
    CellConstraints cc = new CellConstraints();
    DefaultFormBuilder fb = new DefaultFormBuilder(layout, Translation.INSTANCE.getBundle());

    fb.add(slider, cc.xy(1, 1));
    fb.add(spinner, cc.xy(2, 1));

    dashboard.add(fb.getPanel(), BorderLayout.CENTER);
    add(dashboard, BorderLayout.SOUTH);
    switchColumn(0);
}

From source file:biomine.bmvis2.pipeline.TwoPhaseExtractOperation.java

@Override
public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) {
    int tot = SimplificationUtils.countNormalEdges(graph);

    if (oldTot != 0) {
        int nt = (target * tot) / oldTot;
        if (nt != target) {
            target = Math.max(nt, target);
        }//from  w  ww .  j  av  a 2 s  .  c o m
    } else {
        target = tot;
    }

    oldTot = tot;
    JPanel ret = new JPanel();

    final JSlider sl = new JSlider(0, tot, Math.min(target, tot));
    sl.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent arg0) {
            if (target == sl.getValue())
                return;
            target = sl.getValue();
            v.settingsChanged(false);

        }
    });
    ret.setLayout(new BoxLayout(ret, BoxLayout.Y_AXIS));
    ret.add(sl);

    return ret;
}

From source file:hr.restart.util.chart.ChartXYZ2.java

void showOptions() {

    if (optionsPanel == null) {

        catSlider = new JSlider(0, 50, iCategoryMargin);
        catSlider.setPaintLabels(true);/*from  w ww.  ja va2s . c  om*/
        catSlider.setPaintTicks(true);
        catSlider.setMajorTickSpacing(10);
        catSlider.setMinorTickSpacing(5);
        catSlider.setSnapToTicks(true);

        colSlider = new JSlider(-80, 20, iColumnMargin);
        colSlider.setPaintLabels(true);
        colSlider.setPaintTicks(true);
        colSlider.setMajorTickSpacing(20);
        colSlider.setMinorTickSpacing(5);
        catSlider.setSnapToTicks(true);

        colFirst = new JLabel("               ");
        colFirst.setOpaque(true);
        colFirst.setBackground(cFirst);

        colSecond = new JLabel("               ");
        colSecond.setOpaque(true);
        colSecond.setBackground(cSecond);

        JButton selFirst = new JButton("...");
        selFirst.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Color ret = JColorChooser.showDialog(ChartXYZ2.this, "Boja prvog stupca", cFirst);
                if (ret != null)
                    colFirst.setBackground(ret);
            }
        });

        JButton selSecond = new JButton("...");
        selSecond.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Color ret = JColorChooser.showDialog(ChartXYZ2.this, "Boja drugog stupca", cSecond);
                if (ret != null)
                    colSecond.setBackground(ret);
            }
        });

        optionsPanel = new JPanel(new GridBagLayout());
        optionsPanel.setBorder(BorderFactory.createEmptyBorder(15, 20, 15, 20));
        GridBagConstraints c = new GridBagConstraints();
        c.weightx = 0.1;
        c.weighty = 1;
        c.gridx = 0;
        c.gridy = 0;
        c.anchor = c.LINE_START;
        c.insets = new Insets(2, 10, 2, 2);
        optionsPanel.add(new JLabel("Razmak izmeu grupa"), c);

        c.gridy = 1;
        optionsPanel.add(new JLabel("Razmak izmeu stupaca   "), c);

        c.gridy = 2;
        optionsPanel.add(new JLabel("Boja prvog stupca"), c);

        c.gridy = 3;
        optionsPanel.add(new JLabel("Boja drugog stupca"), c);

        c.weightx = 0.9;
        c.gridwidth = 2;
        c.gridx = 1;
        c.gridy = 0;
        c.fill = c.HORIZONTAL;
        optionsPanel.add(catSlider, c);

        c.gridy = 1;
        optionsPanel.add(colSlider, c);

        c.weightx = 0;
        c.gridwidth = 1;
        c.gridy = 2;
        c.fill = c.NONE;
        optionsPanel.add(colFirst, c);

        c.gridy = 3;
        optionsPanel.add(colSecond, c);

        c.weightx = 0.9;
        c.gridx = 2;
        c.gridy = 2;
        optionsPanel.add(selFirst, c);

        c.gridy = 3;
        optionsPanel.add(selSecond, c);

    } else {
        catSlider.setValue(iCategoryMargin);
        colSlider.setValue(iColumnMargin);
        colFirst.setBackground(cFirst);
        colSecond.setBackground(cSecond);
    }

    raInputDialog dlg = new raInputDialog();
    if (dlg.show(this, optionsPanel, "Opcije prikaza")) {
        iCategoryMargin = catSlider.getValue();
        iColumnMargin = colSlider.getValue();
        cFirst = colFirst.getBackground();
        cSecond = colSecond.getBackground();
        selectionChanged();
    }
}

From source file:CompositeTest.java

public CompositeTestFrame() {
    setTitle("CompositeTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    canvas = new CompositeComponent();
    add(canvas, BorderLayout.CENTER);

    ruleCombo = new JComboBox(new Object[] { new Rule("CLEAR", "  ", "  "), new Rule("SRC", " S", " S"),
            new Rule("DST", "  ", "DD"), new Rule("SRC_OVER", " S", "DS"), new Rule("DST_OVER", " S", "DD"),
            new Rule("SRC_IN", "  ", " S"), new Rule("SRC_OUT", " S", "  "), new Rule("DST_IN", "  ", " D"),
            new Rule("DST_OUT", "  ", "D "), new Rule("SRC_ATOP", "  ", "DS"), new Rule("DST_ATOP", " S", " D"),
            new Rule("XOR", " S", "D "), });
    ruleCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            Rule r = (Rule) ruleCombo.getSelectedItem();
            canvas.setRule(r.getValue());
            explanation.setText(r.getExplanation());
        }/*from w  w  w. ja v a  2 s  . c  o  m*/
    });

    alphaSlider = new JSlider(0, 100, 75);
    alphaSlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent event) {
            canvas.setAlpha(alphaSlider.getValue());
        }
    });
    JPanel panel = new JPanel();
    panel.add(ruleCombo);
    panel.add(new JLabel("Alpha"));
    panel.add(alphaSlider);
    add(panel, BorderLayout.NORTH);

    explanation = new JTextField();
    add(explanation, BorderLayout.SOUTH);

    canvas.setAlpha(alphaSlider.getValue());
    Rule r = (Rule) ruleCombo.getSelectedItem();
    canvas.setRule(r.getValue());
    explanation.setText(r.getExplanation());
}

From source file:BlendCompositeDemo.java

public BlendCompositeDemo() {
    super("Blend Composites");

    compositeTestPanel = new CompositeTestPanel();
    compositeTestPanel.setComposite(BlendComposite.Average);
    add(compositeTestPanel);//from  w  w w.  j  ava2 s . c o m

    combo = new JComboBox(BlendComposite.BlendingMode.values());
    combo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            compositeTestPanel.setComposite(BlendComposite.getInstance(
                    BlendComposite.BlendingMode.valueOf(combo.getSelectedItem().toString()),
                    slider.getValue() / 100.0f));
        }
    });

    slider = new JSlider(0, 100, 100);
    slider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            BlendComposite blend = (BlendComposite) compositeTestPanel.getComposite();
            blend = blend.derive(slider.getValue() / 100.0f);
            compositeTestPanel.setComposite(blend);
        }
    });

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.LEFT));
    controls.add(combo);
    controls.add(new JLabel("0%"));
    controls.add(slider);
    controls.add(new JLabel("100%"));
    add(controls, BorderLayout.SOUTH);

    pack();
    setLocationRelativeTo(null);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

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);//from  w  ww . j a  v a  2 s.com
    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.jfree.chart.demo.CategoryLabelPositionsDemo1.java

public static JPanel createDemoPanel() {
    CategoryDataset categorydataset = createDataset();
    chart = createChart(categorydataset);
    JPanel jpanel = new JPanel(new BorderLayout());
    JPanel jpanel1 = new JPanel(new BorderLayout());
    JPanel jpanel2 = new JPanel();
    invertCheckBox = new JCheckBox("Invert Range Axis?");
    invertCheckBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent actionevent) {
            CategoryPlot categoryplot = (CategoryPlot) CategoryLabelPositionsDemo1.chart.getPlot();
            categoryplot.getRangeAxis().setInverted(CategoryLabelPositionsDemo1.invertCheckBox.isSelected());
        }/*  www. ja  va2 s .co m*/

    });
    jpanel2.add(invertCheckBox);
    ButtonGroup buttongroup = new ButtonGroup();
    horizontalRadioButton = new JRadioButton("Horizontal", false);
    horizontalRadioButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent actionevent) {
            if (CategoryLabelPositionsDemo1.horizontalRadioButton.isSelected()) {
                CategoryPlot categoryplot = (CategoryPlot) CategoryLabelPositionsDemo1.chart.getPlot();
                categoryplot.setOrientation(PlotOrientation.HORIZONTAL);
            }
        }

    });
    buttongroup.add(horizontalRadioButton);
    verticalRadioButton = new JRadioButton("Vertical", true);
    verticalRadioButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent actionevent) {
            if (CategoryLabelPositionsDemo1.verticalRadioButton.isSelected()) {
                CategoryPlot categoryplot = (CategoryPlot) CategoryLabelPositionsDemo1.chart.getPlot();
                categoryplot.setOrientation(PlotOrientation.VERTICAL);
            }
        }

    });
    buttongroup.add(verticalRadioButton);
    jpanel2.add(horizontalRadioButton);
    jpanel2.add(verticalRadioButton);
    jpanel2.setBorder(new TitledBorder("Plot Settings: "));
    JPanel jpanel3 = new JPanel(new BorderLayout());
    slider = new JSlider(0, 90, 45);
    slider.setMajorTickSpacing(10);
    slider.setMinorTickSpacing(5);
    slider.setPaintLabels(true);
    slider.setPaintTicks(true);
    slider.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent changeevent) {
            CategoryPlot categoryplot = (CategoryPlot) CategoryLabelPositionsDemo1.chart.getPlot();
            CategoryAxis categoryaxis = categoryplot.getDomainAxis();
            categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(
                    ((double) CategoryLabelPositionsDemo1.slider.getValue() * 3.1415926535897931D) / 180D));
        }

    });
    jpanel3.add(slider);
    jpanel3.setBorder(new TitledBorder("Axis Label Rotation Angle:"));
    jpanel1.add("North", jpanel2);
    jpanel1.add(jpanel3);
    jpanel.add(new ChartPanel(chart));
    jpanel.add("South", jpanel1);
    return jpanel;
}