List of usage examples for javax.swing JSlider getValue
public int getValue()
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 w w w. ja 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:org.csml.tommo.sugar.modules.heatmap.MixedHeatmapDialog.java
private JSlider createMixParameterSlider() { JSlider slider = new JSlider(JSlider.VERTICAL, 0, 100, (int) (mixOperation.getParameter() * 100.0)); slider.setMajorTickSpacing(10);//from www . j av a 2 s.c om slider.setSnapToTicks(true); slider.setPaintTicks(true); // slider.setPaintLabels(true); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JSlider source = (JSlider) event.getSource(); if (!source.getValueIsAdjusting()) { double param = (double) source.getValue() / (double) 100.0; updateMixParameter(param); } } }); return slider; }
From source file:DiningPhilosophers.java
public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); grabDelay = source.getValue() * 100; label.setText(String.valueOf(grabDelay + " milliseconds")); }
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 . ja v a2 s. c om } 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: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 av a2 s . 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 w w .j a v a 2 s . c om*/ } 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:de.unibayreuth.bayeos.goat.options.JOptionDialog.java
private void jSliderShapeSizeStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSliderShapeSizeStateChanged JSlider s = (JSlider) evt.getSource(); if (!s.getValueIsAdjusting()) { pref.putInt("shapesize", s.getValue()); }// ww w. java2 s .c o m }
From source file:projects.tgas.exec.HrDiagram.java
/** * Main constructor.//w w w .java 2 s. c om */ public HrDiagram() { tgasStars = TgasUtils.loadTgasCatalogue(); method = METHOD.NAIVE; fMax = 1.0; final JComboBox<METHOD> methodComboBox = new JComboBox<METHOD>(METHOD.values()); methodComboBox.setSelectedItem(method); methodComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { method = (METHOD) methodComboBox.getSelectedItem(); updateChart(); } }); final JSlider fSlider = GuiUtil.buildSlider(0.0, 2.0, 5, "%3.3f"); fSlider.setValue((int) Math.rint(100.0 * fMax / 2.0)); final JLabel fLabel = new JLabel(getFLabel()); // Create a change listener fot these ChangeListener cl = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (source == fSlider) { // Compute fractional parallax error from slider position double newF = (2.0 * source.getValue() / 100.0); fMax = newF; fLabel.setText(getFLabel()); } updateChart(); } }; fSlider.addChangeListener(cl); // Add a bit of padding to space things out fSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); // Present controls below the HR diagram JPanel controls = new JPanel(new GridLayout(2, 2)); controls.add(new JLabel("Distance estimation method:")); controls.add(methodComboBox); controls.add(fLabel); controls.add(fSlider); // Initialise the ChartPanel updateChart(); // Build the panel contents setLayout(new BorderLayout()); add(hrDiagPanel, BorderLayout.CENTER); add(controls, BorderLayout.SOUTH); }
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 ww .ja v a 2 s . c o m public void stateChanged(ChangeEvent arg0) { targetSize = sizeSlider.getValue(); v.settingsChanged(false); } }); return sizeSlider; }
From source file:jku.ss09.mir.lastfmecho.bo.visualization.MirArtistNetworkGraphVisualizer.java
public boolean init() { if (artistList.size() > similarityMatrix.length) { System.out.println(// w w w . j a va 2 s. co m "Error in MirArtistNetworkGraphVisualizer - The similaritymatrix is smaller than number of artists "); return false; } graph = getGraph(SIMILARITY_DEFAULT / 100.0); setVisualizationRenderer(); // create a frome to hold the graph final JFrame frame = new JFrame(); Container content = frame.getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final ModalGraphMouse gm = new DefaultModalGraphMouse<Integer, Number>(); vv.setGraphMouse(gm); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JSlider slider = new JSlider(JSlider.HORIZONTAL, SIMILARITY_MIN, SIMILARITY_MAX, SIMILARITY_DEFAULT); slider.setMajorTickSpacing(10); slider.setPaintTicks(true); final JLabel sliderLabel = new JLabel("0.87"); final MirArtistNetworkGraphVisualizer thisPointer = this; slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent arg0) { JSlider source = (JSlider) arg0.getSource(); if (!source.getValueIsAdjusting()) { System.out.println(source.getValue() / 100.0); Graph testG = getGraph(source.getValue() / 100.0); sliderLabel.setText(Double.toString(source.getValue() / 100.0)); thisPointer.vv.setGraphLayout(new FRLayout<Integer, Number>(testG)); //thisPointer.setVisualizationRenderer(); thisPointer.vv.validate(); thisPointer.vv.repaint(); } } }); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); controls.add(((DefaultModalGraphMouse<Integer, Number>) gm).getModeComboBox()); controls.add(new JLabel("Similarity Limit: ")); controls.add(sliderLabel); controls.add(slider); content.add(controls, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); return true; }