List of usage examples for javax.swing JSlider JSlider
public JSlider(int orientation, int min, int max, int value)
From source file:Main.java
/** * Creates a JSlider and ensure the given value is between min and max. * * @param orientation the orientation of the slider * @param min the minimum value of the slider * @param max the maximum value of the slider * @param value the initial value of the slider * @return the JSlider/*from w w w .j a v a 2 s .c o m*/ */ public static JSlider createSafeSlider(int orientation, int min, int max, int value) { if (value < min) value = min; else if (value > max) value = max; return new JSlider(orientation, min, max, value); }
From source file:Main.java
public Main() { JPanel sliderPanel = new JPanel(); sliderPanel.setLayout(new GridLayout(0, 1)); for (int i = 0; i < slider.length; i++) { labels[i] = new Label(colorNames[i] + 255); sliderPanel.add(labels[i]);//www. j a v a2 s. c o m slider[i] = new JSlider(SwingConstants.HORIZONTAL, 0, 255, 255); slider[i].setMinorTickSpacing(10); slider[i].setMajorTickSpacing(50); slider[i].setPaintTicks(true); slider[i].setPaintLabels(true); sliderPanel.add(slider[i]); } lb = new Label("Colour"); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setModal(true); dialog.add(sliderPanel, BorderLayout.CENTER); dialog.add(lb, BorderLayout.SOUTH); dialog.pack(); dialog.setLocation(200, 200); dialog.setTitle("Colour Dialog"); dialog.setVisible(true); }
From source file:ColorComposite.java
public ColorComposite() { super();//from w ww . java2s . c o m Container container = getContentPane(); canvas = new MyCanvas(); container.add(canvas); JPanel panel = new JPanel(); JLabel label = new JLabel("Color-Composite: "); JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 65); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider tempSlider = (JSlider) e.getSource(); alphaValue = (float) (tempSlider.getValue() / 100.0); textField.setText(Float.toString(alphaValue)); canvas.repaint(); } }); textField = new JTextField("0.65", 4); panel.add(label); panel.add(slider); panel.add(textField); container.add(BorderLayout.SOUTH, panel); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setSize(450, 450); setVisible(true); }
From source file:Main.java
public JSlider getSlider(int min, int max, int init, int mjrTkSp, int mnrTkSp) { JSlider slider = new JSlider(JSlider.HORIZONTAL, min, max, init); slider.setPaintTicks(true);//from w w w . j a v a 2 s . c om slider.setMajorTickSpacing(mjrTkSp); slider.setMinorTickSpacing(mnrTkSp); slider.setPaintLabels(true); slider.addChangeListener(new SliderListener()); return slider; }
From source file:House.java
public House() { super(new BorderLayout()); JPanel controlPanel = new JPanel(new GridLayout(3, 3)); add(controlPanel, BorderLayout.NORTH); controlPanel.add(new JLabel("Translate(dx,dy): ")); sliderTransX = setSlider(controlPanel, JSlider.HORIZONTAL, 0, 300, 150, 100, 50); sliderTransY = setSlider(controlPanel, JSlider.HORIZONTAL, 0, 300, 150, 100, 50); // To control rotation controlPanel.add(new JLabel("Rotate(Theta,ox,oy): ")); sliderRotateTheta = setSlider(controlPanel, JSlider.HORIZONTAL, 0, 360, 0, 90, 45); JPanel subPanel = new JPanel(); subPanel.setLayout(new GridLayout(1, 2)); sliderRotateX = setSlider(subPanel, JSlider.HORIZONTAL, 0, 300, 150, 150, 50); sliderRotateY = setSlider(subPanel, JSlider.HORIZONTAL, 0, 300, 150, 150, 50); controlPanel.add(subPanel);/*from w w w .j a v a 2 s. c o m*/ // To control scaling controlPanel.add(new JLabel("Scale(sx,sy)x10E-2:")); sliderScaleX = setSlider(controlPanel, JSlider.HORIZONTAL, 0, 200, 100, 100, 10); sliderScaleY = setSlider(controlPanel, JSlider.HORIZONTAL, 0, 200, 100, 100, 10); // To control width of line segments JLabel label4 = new JLabel("Width Control:", JLabel.RIGHT); sliderWidth = new JSlider(JSlider.HORIZONTAL, 0, 20, 1); sliderWidth.setPaintTicks(true); sliderWidth.setMajorTickSpacing(5); sliderWidth.setMinorTickSpacing(1); sliderWidth.setPaintLabels(true); sliderWidth.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { width = sliderWidth.getValue(); canvas.repaint(); } }); JPanel widthPanel = new JPanel(); widthPanel.setLayout(new GridLayout(1, 2)); widthPanel.add(label4); widthPanel.add(sliderWidth); add(widthPanel, BorderLayout.SOUTH); canvas = new MyCanvas(); add(canvas, "Center"); }
From source file:org.cds06.speleograph.graph.ValueAxisEditor.java
public ValueAxisEditor(NumberAxis axis) { super();/* ww w. jav a2s . c o m*/ this.axis = axis; this.oldLowValue = axis.getLowerBound(); this.oldHighValue = axis.getUpperBound(); this.maxField = new JTextField(Double.toString(axis.getUpperBound())); this.lowField = new JTextField(Double.toString(axis.getLowerBound())); int max = (int) (axis.getUpperBound() / 5); translateSlider = new JSlider(Adjustable.VERTICAL, -max, max, 0); homotSlider = new JSlider(Adjustable.VERTICAL, -max, max, 0); construct(); setTitle(I18nSupport.translate("graph.valueAxisEditor")); }
From source file:components.SliderDemo2.java
public SliderDemo2() { super(new BorderLayout()); delay = 1000 / FPS_INIT;/* w ww . ja v a 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;//www .java2 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:SliderControlPaintLine.java
public JSlider createSlider(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);/* w w w . j a v a 2 s .com*/ slider.setMajorTickSpacing(majorTickSpacing); slider.setMinorTickSpacing(minorTickSpacing); slider.setPaintLabels(true); slider.addChangeListener(new SliderListener()); panel.add(slider); return slider; }
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 w w w . j av a 2 s .co 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; }