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 ...

Get Java Swing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.