Updating position of JSlider Swing?

Provided that you've correctly configured a minimum and maximum value setValue() will work. The JSlider does need an opportunity to redraw, so make sure you're not tying up the event dispatch thread If your code is responding to any UI event, you're on the dispatch thread and should return as soon as possible.

Provided that you've correctly configured a minimum and maximum value, setValue() will work. The JSlider does need an opportunity to redraw, so make sure you're not tying up the event dispatch thread. If your code is responding to any UI event, you're on the dispatch thread and should return as soon as possible.

Perform any expensive calculations on a background thread. There are a plethora of excellent tutorials for this on the web.

The setValue method definitely does work, so I would check that the value that you're passing in to setValue is indeed within the minimum and maximum value that you've configured the slider with (ie check that you're not passing a percentage value in instead of an integer). A second thing to watch out for: you should only be calling setValue on the event dispatching thread. Of course you can calculate the value that is going to be passed to setValue outside of the even dispatching thread, but any update to a value in a Swing component should be done in the even dispatching thread (ie using SwingUtilities.

InvokeLater).

I am facing the same issue and wonder why setValue is not working on the code I was working on. Here is a short example that works. Import java.awt.

GridBagConstraints; import java.awt. GridBagLayout; import javax.swing. JFrame; import javax.swing.

JLabel; import javax.swing. JSlider; import javax.swing. SwingUtilities; import javax.swing.event.

ChangeEvent; import javax.swing.event. ChangeListener; /** * Write a description of class SSCCESlider here. * * @author (your name) * @version (a version number or a date) */ public class SSCCESlider { public static void main(String args) { JFrame frame = new JFrame("Example"); frame.

SetLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); final JLabel label = new JLabel(); c. Fill = GridBagConstraints. HORIZONTAL; c.

Gridx = 0; c. Gridy = 0; c. Gridwidth = 1; frame.

Add(label, c); JSlider boxSizeSlider = new JSlider(JSlider. HORIZONTAL, 10, 45, 40); c. Fill = GridBagConstraints.

HORIZONTAL; c. Gridx = 0; c. Gridy = 1; c.

Gridwidth = 1; boxSizeSlider. SetMajorTickSpacing(10); boxSizeSlider. SetPaintTicks(true); boxSizeSlider.

SetPaintLabels(true); boxSizeSlider. AddChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { final JSlider source = (JSlider) e.getSource(); if (!source. GetValueIsAdjusting()) { label.

SetText(source.getValue() + ""); if (source.getValue() SetValue(30); // wouldnt work // try { // SwingUtilities. InvokeAndWait(new Runnable() { // public void run() { // source. SetValue(30); // } // }); // } catch (InterruptedException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // } catch (InvocationTargetException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // } } } } }); boxSizeSlider.getModel().

SetValue(30); frame. Add(boxSizeSlider, c); label. SetText(boxSizeSlider.getValue() + ""); frame.pack(); frame.

SetVisible(true); frame. SetDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); } }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions