List of usage examples for javax.swing JSlider JSlider
public JSlider(int orientation, int min, int max, int value)
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(JSlider.VERTICAL, minimum, maximum, initValue); }
From source file:RegisterChangeListenerToJSlider.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSlider framesPerSecond = new JSlider(JSlider.HORIZONTAL, 10, 100, 20); framesPerSecond.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (!source.getValueIsAdjusting()) { int fps = (int) source.getValue(); System.out.println(fps); }//www . j a v a2 s .c o m } }); frame.add(framesPerSecond, "North"); frame.setSize(300, 200); frame.setVisible(true); }
From source file:ScrollSlider.java
public static void main(String args[]) { JFrame f = new JFrame("Change Slider"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSlider aJSlider = new JSlider(JSlider.HORIZONTAL, 0, 1000, 500); ChangeListener aChangeListener = new BoundedChangeListener(); aJSlider.addChangeListener(aChangeListener); Container c = f.getContentPane(); c.add(aJSlider, BorderLayout.SOUTH); f.setSize(300, 200);// ww w . j ava 2 s . c o m f.setVisible(true); }
From source file:DynamicIconExample.java
public static void main(String[] args) { final JSlider width = new JSlider(JSlider.HORIZONTAL, 1, 150, 75); final JSlider height = new JSlider(JSlider.VERTICAL, 1, 150, 75); class DynamicIcon implements Icon { public int getIconWidth() { return width.getValue(); }/*ww w . j a va2 s .c o m*/ public int getIconHeight() { return height.getValue(); } public void paintIcon(Component c, Graphics g, int x, int y) { g.fill3DRect(x, y, getIconWidth(), getIconHeight(), true); } } Icon icon = new DynamicIcon(); final JLabel dynamicLabel = new JLabel(icon); class Updater implements ChangeListener { public void stateChanged(ChangeEvent ev) { dynamicLabel.repaint(); } } Updater updater = new Updater(); width.addChangeListener(updater); height.addChangeListener(updater); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = f.getContentPane(); c.setLayout(new BorderLayout()); c.add(width, BorderLayout.NORTH); c.add(height, BorderLayout.WEST); c.add(dynamicLabel, BorderLayout.CENTER); f.setSize(210, 210); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel main = new JPanel(new GridLayout(2, 1)); JPanel scrollBarPanel = new JPanel(); final JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL, 0, 48, 0, 255); int height = scrollBar.getPreferredSize().height; scrollBar.setPreferredSize(new Dimension(175, height)); scrollBarPanel.add(scrollBar);/* ww w. j a va 2 s.c o m*/ main.add(scrollBarPanel); JPanel sliderPanel = new JPanel(); final JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 255, 128); slider.setMajorTickSpacing(48); slider.setMinorTickSpacing(16); slider.setPaintTicks(true); sliderPanel.add(slider); main.add(sliderPanel); frame.add(main, BorderLayout.CENTER); scrollBar.addAdjustmentListener(new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { System.out.println("JScrollBar's current value = " + scrollBar.getValue()); } }); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { System.out.println("JSlider's current value = " + slider.getValue()); } }); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
public static JSlider getSlider(int w, int h, String name, int minValue, int maxValue) { JSlider slider = new JSlider(JSlider.HORIZONTAL, minValue, maxValue, ((maxValue + minValue) / 2)); slider.setFont(getFont());//from www.j a v a 2s. c o m slider.setPreferredSize(getSliderDimension(w, h)); slider.setMinimumSize(getSliderDimension(w, h)); slider.setName(name); return slider; }
From source file:Main.java
public static JSlider getSlider(int w, int h, String name, int minValue, int maxValue, int initValue) { JSlider slider = new JSlider(JSlider.HORIZONTAL, minValue, maxValue, initValue); slider.setFont(getFont());//w ww. ja v a 2 s . c om slider.setPreferredSize(getSliderDimension(w, h)); slider.setMinimumSize(getSliderDimension(w, h)); slider.setName(name); return slider; }
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 . j a va 2 s . c o m*/ 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);/*from w w w . j av a 2s .c o m*/ 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 w w w.j ava 2 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); }