List of usage examples for javax.swing JSlider addChangeListener
public void addChangeListener(ChangeListener l)
From source file:SliderTest.java
/** * Adds a slider to the slider panel and hooks up the listener * @param s the slider/*from w w w . j a v a 2s . co m*/ * @param description the slider description */ public void addSlider(JSlider s, String description) { s.addChangeListener(listener); JPanel panel = new JPanel(); panel.add(s); panel.add(new JLabel(description)); sliderPanel.add(panel); }
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 ww w . java 2 s .co 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:AlphaCompositeDemo.java
public AlphaCompositeDemo() { super();//from w w w .j a v a2 s . c om Container container = getContentPane(); canvas = new MyCanvas(); container.add(canvas); rulesBox = new JComboBox(rulesLabels); rulesBox.setSelectedIndex(0); rulesBox.setAlignmentX(Component.LEFT_ALIGNMENT); rulesBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox cb = (JComboBox) e.getSource(); canvas.compositeRule = rules[cb.getSelectedIndex()]; canvas.repaint(); } }); slider.setPaintTicks(true); slider.setMajorTickSpacing(25); slider.setMinorTickSpacing(25); slider.setPaintLabels(true); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider slider = (JSlider) e.getSource(); canvas.alphaValue = (float) slider.getValue() / 100; canvas.repaint(); } }); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(1, 3)); panel.add(rulesBox); panel.add(new JLabel("Alpha Adjustment x E-2: ", JLabel.RIGHT)); panel.add(slider); container.add(panel, BorderLayout.SOUTH); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setSize(500, 300); setVisible(true); }
From source file:biomine.bmvis2.pipeline.RepresentiveHighlightOperation.java
public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) { final JSlider slider = new JSlider(0, graph.getRootNode().getDescendants().size(), 0); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { numberOfNodes = slider.getValue(); v.settingsChanged(false);//from w w w . j a va 2s. c om } }); return slider; }
From source file:biomine.bmvis2.pipeline.EdgeSimplificationOperation.java
public JComponent getSettingsComponent(final SettingsChangeCallback settingsChangeCallback, VisualGraph graph) { this.graph = graph; int edgeCount = SimplificationUtils.countNormalEdges(graph); if (oldEdgeCount != 0) { long newTarget = (this.target * edgeCount) / this.oldEdgeCount; if (newTarget != this.target) { this.target = Math.max(newTarget, this.target); Logging.info("simplifier", "New edge count target: " + this.target); }/*from w ww . ja va 2 s.c o m*/ } else this.target = edgeCount; this.oldEdgeCount = edgeCount; JPanel ret = new JPanel(); final JSlider sl = new JSlider(0, edgeCount, (int) Math.min(target, edgeCount)); sl.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { if (target == sl.getValue()) return; target = sl.getValue(); if (EdgeSimplificationOperation.this.getGraph() == null) settingsChangeCallback.settingsChanged(false); else EdgeSimplificationOperation.this.hideHidables(EdgeSimplificationOperation.this.getGraph()); } }); ret.setLayout(new BoxLayout(ret, BoxLayout.Y_AXIS)); ret.add(sl); ret.add(costLabel); return ret; }
From source file:components.SliderDemo2.java
public SliderDemo2() { super(new BorderLayout()); delay = 1000 / FPS_INIT;/*from w w w .j av a 2 s .c om*/ //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;//from w ww. j ava 2 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:biomine.bmvis2.pipeline.SizeSliderOperation.java
@Override public JComponent getSettingsComponent(final SettingsChangeCallback v, final VisualGraph graph) { final JSlider sizeSlider; sizeSlider = new JSlider(0, graph.getAllNodes().size() + 10); sizeSlider.setValue(graph.getNodes().size()); sizeSlider.addChangeListener(new ChangeListener() { @Override// w w w . j a v a 2s . c o m public void stateChanged(ChangeEvent arg0) { targetSize = sizeSlider.getValue(); v.settingsChanged(false); } }); return sizeSlider; }
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);/*w w w. jav a2 s . co m*/ slider.setMajorTickSpacing(mjrTkSp); slider.setMinorTickSpacing(mnrTkSp); slider.setPaintLabels(true); slider.addChangeListener(new SliderListener()); return slider; }
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);//ww w.ja v a2 s . com slider.setMajorTickSpacing(majorTickSpacing); slider.setMinorTickSpacing(minorTickSpacing); slider.setPaintLabels(true); slider.addChangeListener(new SliderListener()); panel.add(slider); return slider; }