List of usage examples for javax.swing JSlider setValue
@BeanProperty(bound = false, preferred = true, description = "The sliders current value.") public void setValue(int n)
From source file:Main.java
public static void main(String[] argv) throws Exception { JSlider slider = new JSlider(); slider.setValue(27); int value = slider.getValue(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JSlider slider = new JSlider(); int newValue = 33; slider.setValue(newValue); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSlider oneJSlider = new JSlider(); oneJSlider.setValue(27); int value = oneJSlider.getValue(); System.out.println(value);// w w w . j a v a 2 s . co m oneJSlider.setPaintTicks(true); frame.add(oneJSlider, BorderLayout.NORTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void setupSl(JSlider sl, int minorTickSpacing, int maximum) { sl.setMaximum(maximum);/*from www . j a v a 2 s . co m*/ sl.setMinorTickSpacing(minorTickSpacing); sl.setPaintLabels(true); sl.setPaintTicks(true); sl.setValue(0); }
From source file:Main.java
/** * Creates a JSlider built//w ww.jav a 2s .com * using a {@link DefaultBoundedRangeModel} and * containing a {@link MouseWheelListener} * and some usual default settings * * @param model * @return the corresponding {@link JSlider} */ public static JSlider createJSlider(final BoundedRangeModel model) { final JSlider slider = new JSlider(model); slider.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { slider.setValue(-e.getWheelRotation() * model.getMaximum() / 100 + model.getValue()); } }); slider.setPaintTicks(true); slider.setPaintLabels(true); // slider.setMajorTickSpacing(model.getMaximum()/2); // slider.setMinorTickSpacing(model.getMaximum()/10); // slider.setSnapToTicks(true); return slider; }
From source file:MainClass.java
public MainClass() { Container cp = new Box(BoxLayout.X_AXIS); setContentPane(cp);/*from ww w . j a v a 2s . co m*/ JPanel firstPanel = new JPanel(); propertyComboBox = new JComboBox(); propertyComboBox.addItem("text"); propertyComboBox.addItem("font"); propertyComboBox.addItem("background"); propertyComboBox.addItem("foreground"); firstPanel.add(propertyComboBox); cp.add(firstPanel); cp.add(Box.createGlue()); tf = new JTextField("Hello"); tf.setForeground(Color.RED); tf.setDragEnabled(true); cp.add(tf); cp.add(Box.createGlue()); l = new JLabel("Hello"); l.setBackground(Color.YELLOW); cp.add(l); cp.add(Box.createGlue()); JSlider stryder = new JSlider(SwingConstants.VERTICAL); stryder.setMinimum(10); stryder.setValue(14); stryder.setMaximum(72); stryder.setMajorTickSpacing(10); stryder.setPaintTicks(true); cp.add(stryder); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 300); setMyTransferHandlers((String) propertyComboBox.getSelectedItem()); MouseListener myDragListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { JComponent c = (JComponent) e.getSource(); TransferHandler handler = c.getTransferHandler(); handler.exportAsDrag(c, e, TransferHandler.COPY); } }; l.addMouseListener(myDragListener); propertyComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ce) { JComboBox bx = (JComboBox) ce.getSource(); String prop = (String) bx.getSelectedItem(); setMyTransferHandlers(prop); } }); tf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JTextField jtf = (JTextField) evt.getSource(); String fontName = jtf.getText(); Font font = new Font(fontName, Font.BOLD, 18); tf.setFont(font); } }); stryder.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { JSlider sl = (JSlider) evt.getSource(); Font oldf = tf.getFont(); Font newf = oldf.deriveFont((float) sl.getValue()); tf.setFont(newf); } }); }
From source file:biomine.bmvis2.pipeline.EdgeGoodnessHider.java
public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) { double maxEdge = 0; for (VisualEdge e : graph.getAllEdges()) { maxEdge = Math.max(maxEdge, e.getGoodness()); }/* ww w .j a va 2 s .c o m*/ final int scale = 100; final JSlider limitSlider = new JSlider(); limitSlider.setMinimum(0); limitSlider.setMaximum(scale); limitSlider.setValue((int) (limit * scale)); final JTextField limitText = new JTextField(); limitText.setEditable(false); limitText.setText("" + limit); limitSlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { limit = limitSlider.getValue() / (double) scale; limitText.setText("" + limit); v.settingsChanged(false); } }); JPanel ret = new JPanel(); GridBagLayout bag = new GridBagLayout(); ret.setLayout(bag); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.fill = c.HORIZONTAL; ret.add(limitSlider, c); c.gridy++; ret.add(limitText, c); return ret; }
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//from ww w .j av a 2 s .c o m public void stateChanged(ChangeEvent arg0) { targetSize = sizeSlider.getValue(); v.settingsChanged(false); } }); return sizeSlider; }
From source file:Transfer.java
public Transfer() { // Establish the GUI Container cp = new Box(BoxLayout.X_AXIS); setContentPane(cp);//from ww w. j a va 2 s . c o m JPanel firstPanel = new JPanel(); propertyComboBox = new JComboBox(); propertyComboBox.addItem("text"); propertyComboBox.addItem("font"); propertyComboBox.addItem("background"); propertyComboBox.addItem("foreground"); firstPanel.add(propertyComboBox); cp.add(firstPanel); cp.add(Box.createGlue()); tf = new JTextField("Hello"); tf.setForeground(Color.RED); tf.setDragEnabled(true); cp.add(tf); cp.add(Box.createGlue()); l = new JLabel("Hello"); l.setBackground(Color.YELLOW); cp.add(l); cp.add(Box.createGlue()); JSlider stryder = new JSlider(SwingConstants.VERTICAL); stryder.setMinimum(10); stryder.setValue(14); stryder.setMaximum(72); stryder.setMajorTickSpacing(10); stryder.setPaintTicks(true); cp.add(stryder); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 300); // Add Listeners and Converters setMyTransferHandlers((String) propertyComboBox.getSelectedItem()); // Mousing in the Label starts a Drag. MouseListener myDragListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { JComponent c = (JComponent) e.getSource(); TransferHandler handler = c.getTransferHandler(); handler.exportAsDrag(c, e, TransferHandler.COPY); } }; l.addMouseListener(myDragListener); // Selecting in the ComboBox makes that the property that is xfered. propertyComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ce) { JComboBox bx = (JComboBox) ce.getSource(); String prop = (String) bx.getSelectedItem(); setMyTransferHandlers(prop); } }); // Typing a word and pressing enter in the TextField tries // to set that as the font name. tf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JTextField jtf = (JTextField) evt.getSource(); String fontName = jtf.getText(); Font font = new Font(fontName, Font.BOLD, 18); tf.setFont(font); } }); // Setting the Slider sets that font into the textfield. stryder.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { JSlider sl = (JSlider) evt.getSource(); Font oldf = tf.getFont(); Font newf = oldf.deriveFont((float) sl.getValue()); tf.setFont(newf); } }); }
From source file:projects.tgas.exec.HrDiagram.java
/** * Main constructor.//w ww . ja va 2 s . c o m */ 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); }