
Scrollbar.VERTICAL, 0, 8, -100, 100); what are each values for?

Hello Friend,
The code specifies the orientation, initial value of bar, visible amount, and minimum and maximum values.
We are providing you the code through which you can understand easily.
import java.awt.*;
import java.awt.event.*;
public class ScrollbarExample extends Panel {
Label label;
public ScrollbarExample() {
label=new Label();
setLayout(new BorderLayout());
Scrollbar bar1 = new Scrollbar(Scrollbar.HORIZONTAL, 30, 20, 0, 300);
Scrollbar bar2 = new Scrollbar(Scrollbar.VERTICAL, 0, 8, -100, 100);
bar1.setUnitIncrement(2);
bar1.setBlockIncrement(1);
bar1.addAdjustmentListener(new Listener());
bar2.addAdjustmentListener(new Listener());
add(bar1, BorderLayout.SOUTH);
add(bar2, BorderLayout.EAST);
add(label, BorderLayout.CENTER);
Frame frame = new Frame("Scroll Bar Example");
frame.add(this);
frame.setSize(200,200);
frame.setVisible(true);
}
class Listener implements AdjustmentListener {
public void adjustmentValueChanged(AdjustmentEvent e) {
label.setText("Value is " + e.getValue() +"");
repaint();
}
}
public static void main(String s[]) {
new ScrollbarExample();
}
}
In the above code using the Scrollbar class we have defined both the bars. In the vertical bar, we have taken your values. When you will run the above code, you will find that vertical bar has the values from -100 to 100. The bar is set to O as initial value and 8 is the visible amount.
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.