The Bounded-Range Model

Components that use 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 javax.swing.BoundedRangeModel interface outlines the data model for such an object. Objects implementing the BoundedRangeModel interface must contain an adjustable integer value, an extent, a minimum, and a maximum. Swing contains three bounded-range components: JScrollBar, JSlider, and JProgressBar. These components are shown in Figure 6-1.

Bounded-range components in Swing

Figure 6-1. Bounded-range components in Swing

Properties

Table 6-1 shows the properties of the BoundedRangeModel interface.

Table 6-1. BoundedRangeModel properties

Property

Data type

get

is

set

Default value

extent

int

·

 

·

 

maximum

int

·

 

·

 

minimum

int

·

 

·

 

value

int

·

 

·

 

valueIsAdjusting

boolean

·

 

·

 

The minimum , maximum, and value properties form the actual bounded range. The extent property can give the value its ...

Get Java Swing, 2nd Edition 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.