Java Code Examples for javax.swing.JSlider#setValue()
The following examples show how to use
javax.swing.JSlider#setValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Query.java From opt4j with MIT License | 6 votes |
/** * Set the position of an item that has been added using addSlider. Notify * listeners that the value has changed. * * @param name * The name of the entry. * @param value * The value to set the slider position. * @exception NoSuchElementException * If there is no item with the specified name. Note that * this is a runtime exception, so it need not be declared * explicitly. * @exception IllegalArgumentException * If the entry is not a slider. This is a runtime exception, * so it need not be declared explicitly. */ public void setSlider(String name, int value) { Object result = _entries.get(name); if (result == null) { throw new NoSuchElementException("No item named \"" + name + " \" in the query box."); } if (result instanceof JSlider) { JSlider theSlider = (JSlider) result; // Set the new slider position. theSlider.setValue(value); } else { throw new IllegalArgumentException( "Item named \"" + name + "\" is not a slider, and hence cannot be set using " + "setSlider()."); } _notifyListeners(name); }
Example 2
Source File: TimeSeriesPlayerForm.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
private JSlider createSpeedSlider() { final JSlider speedSlider = new JSlider(1, 10); speedSlider.setToolTipText("Choose the playing speed"); speedSlider.setSnapToTicks(true); speedSlider.setPaintTrack(true); speedSlider.setPaintTicks(true); speedSlider.setPaintLabels(true); speedSlider.setValue(6); speedSlider.setPreferredSize(new Dimension(80, speedSlider.getPreferredSize().height)); speedSlider.addChangeListener(e -> { timerDelay = calculateTimerDelay(); timer.setDelay(timerDelay); updateSpeedUnit(); }); return speedSlider; }
Example 3
Source File: ViewElementColor.java From Robot-Overlord-App with GNU General Public License v2.0 | 6 votes |
private JSlider addField(float value,JPanel parent,String labelName,GridBagConstraints gbc) { JSlider field = new JSlider(); field.setMaximum(255); field.setMinimum(0); field.setMinorTickSpacing(1); field.setValue((int)(value*255)); field.addChangeListener(this); field.addFocusListener(this); JLabel label = new JLabel(labelName,JLabel.LEADING); JPanel panel = new JPanel(new BorderLayout()); panel.add(label,BorderLayout.LINE_START); panel.add(field,BorderLayout.LINE_END); parent.add(panel,gbc); return field; }
Example 4
Source File: ViewElementSliderDouble.java From Robot-Overlord-App with GNU General Public License v2.0 | 6 votes |
public ViewElementSliderDouble(RobotOverlord ro,DoubleEntity e,int top,int bottom) { super(ro); this.e=e; e.addObserver(this); field = new JSlider(); field.setMaximum(top); field.setMinimum(bottom); field.setMinorTickSpacing(1); field.setValue((int)Math.floor(e.get())); field.addChangeListener(this); field.addFocusListener(this); JLabel label = new JLabel(e.getName(),JLabel.LEADING); value = new JLabel(Integer.toString(field.getValue()),JLabel.RIGHT); Dimension dim = new Dimension(30,1); value.setMinimumSize(dim); value.setPreferredSize(dim); value.setMaximumSize(dim); panel.setLayout(new BorderLayout()); panel.add(label,BorderLayout.LINE_START); panel.add(field,BorderLayout.CENTER); panel.add(value,BorderLayout.LINE_END); }
Example 5
Source File: DefaultProductLayer.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
public JPanel getControlPanel(final WorldWindowGLCanvas wwd) { final JSlider opacitySlider = new JSlider(); opacitySlider.setMaximum(100); opacitySlider.setValue((int) (getOpacity() * 100)); opacitySlider.setEnabled(true); opacitySlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { int value = opacitySlider.getValue(); setOpacity(value / 100d); wwd.repaint(); } }); //theSelectedObjectLabel = new JLabel("Selected: "); final JPanel opacityPanel = new JPanel(new BorderLayout(5, 5)); opacityPanel.add(new JLabel("Opacity"), BorderLayout.WEST); opacityPanel.add(opacitySlider, BorderLayout.CENTER); return opacityPanel; }
Example 6
Source File: ChartPanel.java From javamelody with Apache License 2.0 | 6 votes |
private JSlider createSlider() { final JSlider slider = new JSlider(); slider.setOpaque(false); slider.setMinimum(10); slider.setMaximum(200); slider.setValue(100); slider.setLabelTable(slider.createStandardLabels(50)); slider.setMajorTickSpacing(100); slider.setMinorTickSpacing(10); slider.setExtent(20); // slider.setPaintLabels(true); // slider.setPaintTicks(true); // slider.setSnapToTicks(true); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { final int value = slider.getValue(); refreshZoom(value); } }); return slider; }
Example 7
Source File: FuzzOptionsPanel.java From zap-extensions with Apache License 2.0 | 6 votes |
private static JSlider createDefaultFuzzDelayInMsSlider( int defaultDelayInMs, int maxDelayInMs, final JLabel currentValueFeedbackLabel) { final JSlider delaySlider = new JSlider(); delaySlider.setMinimum(0); delaySlider.setValue(defaultDelayInMs); delaySlider.setMaximum(maxDelayInMs); delaySlider.setMinorTickSpacing(25); delaySlider.setMajorTickSpacing(100); delaySlider.setPaintTicks(true); delaySlider.setPaintLabels(true); delaySlider.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { currentValueFeedbackLabel.setText(Integer.toString(delaySlider.getValue())); } }); return delaySlider; }
Example 8
Source File: FuzzerOptionsPanel.java From zap-extensions with Apache License 2.0 | 6 votes |
private static JSlider createDefaultFuzzDelayInMsSlider( int delayInMs, int maxDelayInMs, final JLabel currentValueFeedbackLabel) { final JSlider delaySlider = new JSlider(); delaySlider.setMinimum(0); delaySlider.setValue(delayInMs); delaySlider.setMaximum(maxDelayInMs); delaySlider.setMinorTickSpacing(25); delaySlider.setMajorTickSpacing(100); delaySlider.setPaintTicks(true); delaySlider.setPaintLabels(true); delaySlider.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { currentValueFeedbackLabel.setText(Integer.toString(delaySlider.getValue())); } }); return delaySlider; }
Example 9
Source File: AngleSliderUI.java From pumpernickel with MIT License | 6 votes |
@Override public void mousePressed(MouseEvent e) { JSlider slider = (JSlider) e.getComponent(); if (slider.isEnabled() == false) return; if (slider.isRequestFocusEnabled()) { slider.requestFocus(); } Data data = getData(slider); slider.setValueIsAdjusting(true); float centerX = (float) data.dial.getCenterX(); float centerY = (float) data.dial.getCenterY(); double angle = Math.atan2(e.getY() - centerY, e.getX() - centerX); angle = angle / (2 * Math.PI); if (angle < 0) angle += 1; int v = (int) (angle * (slider.getMaximum() - slider.getMinimum()) + slider.getMinimum()); slider.setValue(v); data.mousePressed = true; e.consume(); }
Example 10
Source File: PercentageOptionUI.java From freecol with GNU General Public License v2.0 | 6 votes |
/** * Creates a new {@code PercentageOptionUI} for the given * {@code PercentageOption}. * * @param option The {@code PercentageOption} to make a user * interface for. * @param editable boolean whether user can modify the setting */ public PercentageOptionUI(final PercentageOption option, boolean editable) { super(option, editable); JSlider slider = getComponent(); slider.setModel(new DefaultBoundedRangeModel(option.getValue(), 0, 0, 100)); Hashtable<Integer, JComponent> labels = new Hashtable<>(); labels.put(0, new JLabel("0 %")); labels.put(25, new JLabel("25 %")); labels.put(50, new JLabel("50 %")); labels.put(75, new JLabel("75 %")); labels.put(100, new JLabel("100 %")); slider.setLabelTable(labels); slider.setValue(option.getValue()); slider.setMajorTickSpacing(5); slider.setSnapToTicks(false); }
Example 11
Source File: RangeOptionUI.java From freecol with GNU General Public License v2.0 | 6 votes |
/** * Creates a new {@code RangeOptionUI} for the given * {@code RangeOption}. * * @param option The {@code RangeOption} to make a user interface for * @param editable boolean whether user can modify the setting */ public RangeOptionUI(final RangeOption option, boolean editable) { super(option, editable); JSlider slider = getComponent(); slider.setModel(new DefaultBoundedRangeModel(option.getValueRank(), 0, 0, option.getItemValues().size()-1)); Hashtable<Integer, JComponent> labels = new Hashtable<>(); int index = 0; for (String string : option.getItemValues().values()) { if (option.localizeLabels()) { labels.put(index, Utility.localizedLabel(string)); } else { labels.put(index, new JLabel(string)); } index++; } slider.setLabelTable(labels); slider.setValue(option.getValueRank()); slider.setMajorTickSpacing(1); slider.setSnapToTicks(true); }
Example 12
Source File: Query.java From OpenDA with GNU Lesser General Public License v3.0 | 6 votes |
/** Set the position of an item that has been added using * addSlider. Notify listeners that the value has changed. * @param name The name of the entry. * @param value The value to set the slider position. * @exception NoSuchElementException If there is no item with the * specified name. Note that this is a runtime exception, so it * need not be declared explicitly. * @exception IllegalArgumentException If the entry is not a * slider. This is a runtime exception, so it * need not be declared explicitly. */ public void setSlider(String name, int value) { Object result = _entries.get(name); if (result == null) { throw new NoSuchElementException( "No item named \"" + name + " \" in the query box."); } if (result instanceof JSlider) { JSlider theSlider = (JSlider) result; // Set the new slider position. theSlider.setValue(value); } else { throw new IllegalArgumentException( "Item named \"" + name + "\" is not a slider, and hence cannot be set using " + "setSlider()."); } _notifyListeners(name); }
Example 13
Source File: SoundSettings.java From stendhal with GNU General Public License v2.0 | 5 votes |
/** * Create a volume slider for the master channel. * * @return master volume slider slider */ private JSlider createMasterVolumeSlider() { JSlider slider = new JSlider(0, 100); float volume = ClientSingletonRepository.getSound().getVolume(); slider.setValue(Numeric.floatToInt(volume, 100f)); slider.addChangeListener(new MasterVolumeListener()); return slider; }
Example 14
Source File: SoundSettings.java From stendhal with GNU General Public License v2.0 | 5 votes |
/** * Create a volume slider, and initialize its value from the volume of a * channel. * * @param channel channel corresponding to the slider * @return volume slider for the channel */ private JSlider createVolumeSlider(String channel) { JSlider slider = new JSlider(0, 100); SoundGroup group = ClientSingletonRepository.getSound().getGroup(channel); slider.setValue(Numeric.floatToInt(group.getVolume(), 100f)); slider.addChangeListener(new ChannelChangeListener(channel, group)); return slider; }
Example 15
Source File: LargeNavigationPanelUI.java From pumpernickel with MIT License | 5 votes |
protected void updateSliderState(JSlider slider) { sliderAdjusting++; try { boolean useSlider = false; if (spinner.getModel() instanceof SpinnerNumberModel) { useSlider = true; SpinnerNumberModel numberModel = (SpinnerNumberModel) spinner .getModel(); Number min = (Number) numberModel.getMinimum(); Number max = (Number) numberModel.getMaximum(); float range = max.floatValue() - min.floatValue(); float pos = (((Number) numberModel.getValue()).floatValue() - min .floatValue()) / range; int sliderRange = slider.getMaximum() - slider.getMinimum(); int sliderValue = (int) (pos * sliderRange + slider .getMinimum()); slider.setValue(sliderValue); } if (useSlider != slider.isVisible()) slider.setVisible(useSlider); if (useSlider != firstButton.isVisible()) firstButton.setVisible(useSlider); if (useSlider != lastButton.isVisible()) lastButton.setVisible(useSlider); if (useSlider == getLabel().isVisible()) getLabel().setVisible(!useSlider); } finally { sliderAdjusting--; } }
Example 16
Source File: Sepia.java From marvinproject with GNU Lesser General Public License v3.0 | 5 votes |
public void keyReleased(KeyEvent e) { JTextField txtValor = (JTextField) (attributesPanel.getComponent("txtValue").getComponent()); JSlider barra = (JSlider) (attributesPanel.getComponent("hsIntensidade").getComponent()); try { barra.setValue(Integer.parseInt(txtValor.getText().trim())); } catch (Exception exception) { barra.setValue(0); txtValor.setText("0"); } }
Example 17
Source File: PaddingInfo.java From pumpernickel with MIT License | 5 votes |
/** * Should be called shortly after <code>prep()</code>. */ private static void restore(Component c) { if (c instanceof JComponent) { JComponent jc = (JComponent) c; Boolean b = (Boolean) jc.getClientProperty(USED_TO_BE_OPAQUE); if (b != null && b.booleanValue()) { jc.setOpaque(true); } jc.putClientProperty(USED_TO_BE_OPAQUE, null); Dimension d = (Dimension) jc.getClientProperty(SIZE); if (d != null) { jc.setSize(d); jc.putClientProperty(SIZE, null); } } if (c instanceof JSlider) { JSlider s = (JSlider) c; ChangeListener[] listeners = (ChangeListener[]) s .getClientProperty(CHANGE_LISTENERS); Integer i = (Integer) s.getClientProperty(SLIDER_VALUE); if (i != null) s.setValue(i.intValue()); if (listeners != null) { for (int a = 0; a < listeners.length; a++) { s.addChangeListener(listeners[a]); } } s.putClientProperty(SLIDER_VALUE, null); s.putClientProperty(CHANGE_LISTENERS, null); } if (c instanceof Container) { Container c2 = (Container) c; for (int a = 0; a < c2.getComponentCount(); a++) { restore(c2.getComponent(a)); } } }
Example 18
Source File: PaddingInfo.java From pumpernickel with MIT License | 5 votes |
/** * This makes some visual changes to the component and its children. Shortly * after calling this method, the <code>restore()</code> method needs to be * called. */ private static void prep(Component c) { if (c instanceof JComponent) { JComponent jc = (JComponent) c; if (jc.isOpaque()) { jc.setOpaque(false); jc.putClientProperty(USED_TO_BE_OPAQUE, Boolean.TRUE); } Dimension preferredSize = c.getPreferredSize(); if (greaterThanOrEqualTo(jc.getSize(), preferredSize) == false) { jc.putClientProperty(SIZE, c.getSize()); jc.setSize(preferredSize); } } if (c instanceof JSlider) { JSlider s = (JSlider) c; ChangeListener[] listeners = s.getChangeListeners(); int mid = (s.getMinimum() + s.getMaximum()) / 2; if (mid != s.getValue()) { s.putClientProperty(CHANGE_LISTENERS, listeners); for (int a = 0; a < listeners.length; a++) { s.removeChangeListener(listeners[a]); } s.putClientProperty(SLIDER_VALUE, new Integer(s.getValue())); s.setValue(mid); } } if (c instanceof Container) { Container c2 = (Container) c; for (int a = 0; a < c2.getComponentCount(); a++) { prep(c2.getComponent(a)); } } if (c.isValid() == false) c.validate(); }
Example 19
Source File: GameToolbar.java From SproutLife with MIT License | 4 votes |
/** * Create the panel. */ public void buildPanel() { setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); horizontalStrut = Box.createHorizontalStrut(20); add(horizontalStrut); JLabel lblZoom = new JLabel("Zoom"); add(lblZoom); //lblZoom.setMinimumSize(new Dimension(100, 14)); zoomSlider = new JSlider(); zoomSlider.setPreferredSize(new Dimension(100, 29)); add(zoomSlider); zoomSlider.setMinorTickSpacing(1); zoomSlider.setMinimum(-5); zoomSlider.setValue(-2); zoomSlider.setMaximum(5); JLabel speedLabel = new JLabel("Speed"); add(speedLabel); speedSlider = new JSlider(); speedSlider.setPreferredSize(new Dimension(100, 29)); speedSlider.setSnapToTicks(true); add(speedSlider); speedSlider.setMinimum(-5); speedSlider.setMaximum(4); speedSlider.setValue(-2); gifStopRecordingButton = new JButton("GIF - Stop Rec."); gifStopRecordingButton.setVisible(false); add(gifStopRecordingButton); startPauseButton = new JButton("Start"); add(startPauseButton); startPauseButton.setMaximumSize(new Dimension(200, 23)); startPauseButton.setPreferredSize(new Dimension(80, 29)); stepButton = new JButton("Step"); stepButton.setPreferredSize(new Dimension(80, 29)); add(stepButton); resetButton = new JButton("Reset"); resetButton.setPreferredSize(new Dimension(80, 29)); add(resetButton); horizontalStrut_1 = Box.createHorizontalStrut(20); add(horizontalStrut_1); }
Example 20
Source File: Plugin.java From marvinproject with GNU Lesser General Public License v3.0 | 4 votes |
public void keyReleased(KeyEvent e) { JTextField txtR = (JTextField) (attributesPanel.getComponent("txtR").getComponent()); JTextField txtG = (JTextField) (attributesPanel.getComponent("txtG").getComponent()); JTextField txtB = (JTextField) (attributesPanel.getComponent("txtB").getComponent()); JSlider barra1 = (JSlider) (attributesPanel.getComponent("hsR").getComponent()); JSlider barra2 = (JSlider) (attributesPanel.getComponent("hsG").getComponent()); JSlider barra3 = (JSlider) (attributesPanel.getComponent("hsB").getComponent()); try { if(e.getSource()==txtR){ barra1.setValue(Integer.parseInt(txtR.getText().toString())); } else{ if(e.getSource()==txtG){ barra2.setValue(Integer.parseInt(txtG.getText().toString())); } else if(e.getSource()==txtB){ barra3.setValue(Integer.parseInt(txtB.getText().toString())); } } } catch (Exception exception) { if(e.getSource()==txtR){ barra1.setValue(0); txtR.setText("0"); } else { if(e.getSource()==txtG){ barra2.setValue(0); txtG.setText("0"); } else{ if(e.getSource()==txtB){ barra3.setValue(0); txtB.setText("0"); } } } } }