Java BoundedRangeModel .getMaximum ()
Syntax
BoundedRangeModel.getMaximum() has the following syntax.
int getMaximum()
Example
In the following code shows how to use BoundedRangeModel.getMaximum() method.
// www.j a va 2 s. co m
import java.awt.BorderLayout;
import javax.swing.BoundedRangeModel;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.JScrollBar;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class Main {
public static void main(String args[]) throws Exception {
ChangeListener changeListener = new BoundedChangeListener();
JScrollBar anotherJScrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
BoundedRangeModel model = anotherJScrollBar.getModel();
model.addChangeListener(changeListener);
System.out.println(model.getMaximum());
JFrame frame = new JFrame("ScrollBars R Us");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(anotherJScrollBar, BorderLayout.NORTH);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
class BoundedChangeListener implements ChangeListener {
public void stateChanged(ChangeEvent changeEvent) {
Object source = changeEvent.getSource();
if (source instanceof BoundedRangeModel) {
BoundedRangeModel aModel = (BoundedRangeModel) source;
if (!aModel.getValueIsAdjusting()) {
System.out.println("Changed: " + aModel.getValue());
}
} else if (source instanceof JSlider) {
JSlider theJSlider = (JSlider) source;
if (!theJSlider.getValueIsAdjusting()) {
System.out.println("Slider changed: " + theJSlider.getValue());
}
} else if (source instanceof JProgressBar) {
JProgressBar theJProgressBar = (JProgressBar) source;
System.out.println("ProgressBar changed: " + theJProgressBar.getValue());
} else {
System.out.println("Something changed: " + source);
}
}
}
Home »
Java Tutorial »
javax.swing »
Java Tutorial »
javax.swing »