Question

I am wondering how I can change my start value of the JSlider I am using.

My code looks like this:

public ScaleController() {
// SLIDER 1:
// --------------------------------------------------------------------
    setOrientation(SwingConstants.VERTICAL);
    addChangeListener(this);
    setMajorTickSpacing(10);
    setPaintTicks(true);
    setMaximum(50);
    setMinimum(-50);

    Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();

    labelTable.put(new Integer(50), new JLabel("Zoom +5"));
    labelTable.put(new Integer(0), new JLabel("Zoom 0"));
    labelTable.put(new Integer(-50), new JLabel("Zoom -5"));
    setLabelTable(labelTable);

    setPaintLabels(true);

@Override
public void stateChanged(ChangeEvent e) {
  Controller.setZoom(getValue());
}

I want the default value to be 0, so it starts in the middle of my slider, but I can't figure out how to do this.

Was it helpful?

Solution

setValue(0) would work in your case check API here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top