Contents

Swinging Duke
Feedback Button
Left ArrowRight Arrow

 

This API describes a new model, named the BoundedRangeModel, which is based on Swing architecture. The BoundedRangeModel corrects some shortcomings of the AWT Adjustable interface that were brought to light during the development of the Scrollbar component for Swing.

For the sake of backwards compatibility, Swing components that implement the Adjustable interface and have counterparts in the AWT world can continue to use the Adjustable interface. But new widgets can also implement the new BoundedRangeModel, and future and deterivative works will be based on this new model. Examples of such dual objects are Slider, ProgressBar, and Scrollbar.

Problems involving the Adjustable interface that are addressed by the new BoundedRangeModel include the following:

The BoundedRangeModel maintains object consistancy by enforcing the following set of rules.

  1. minimum <= maximum
  2. minimum <= value
  3. value <= maximum extent
  4. extent >= 0
  5. extent <= maximum value

Attempts to set invalid values result in the model's silently enforcing the rules. For example:

If the minimum is 5, the maximum is 20 and the extent is 0, and someone attempts to call setValue(30), the new value ise set to 20 (the maximum).


The BoundedRangeModel API

The following is the definition of the BoundedRangeModel interface:

public interface BoundedRangeModel    {
    int getMinimum();
    int getMaximum();
    int getValue();
    int getExtent();

    void setMinimum(int x);
    void setMaximum(int x);
    void setValue(int x);
    void setExtent(int x);

    void addModelChangedListener(ModelChangedListener x);
    void removeModelChangedListener(ModelChangedListener x);
}


Version 0.5. Last modified 09/04/97.
Copyright © 1995-97 Sun Microsystems, Inc. All Rights Reserved.

Sun's Home Page