O'Reilly logo

Java Swing by Dave Wood, Marc Loy, Robert Eckstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6. Bounded Range Components

This chapter groups several Swing components together by the model that drives them: the bounded-range model. Bounded-range components in Swing include JSlider, JProgressBar, and JScrollBar. In addition, we discuss two classes that make use of progress bars: ProgressMonitor and ProgressMonitorInputStream. These classes display status dialogs using a JOptionPane that you can assign to a variety of tasks.

The Bounded-Range Model

Components that make use of the bounded-range model typically consist of an integer value that is constrained within two integer boundaries. The lower boundary, the minimum , should always be less than or equal to the model’s current value. In addition, the model’s value should always be less than the upper boundary, the maximum. The model’s value can cover more than one unit; this size is referred to as its extent . With bounded range, the user is allowed to adjust the value of the model according to the rules of the component. If the value violates any of the rules, the model can adjust the values accordingly.

The interface javax.swing.BoundedRangeModel outlines the data model for such an object. The interface is very similar to the java.awt.Adjustable interface presented in AWT 1.1 and retains many of its characteristics. Objects implementing the BoundedRangeModel interface must contain an adjustable integer value, an extent, and a minimum and maximum. Swing contains three bounded-range components: JScrollBar, JSlider ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required