Methods Summary |
---|
public void | addAdjustmentListener(java.awt.event.AdjustmentListener l)Adds an AdjustmentListener. Adjustment listeners are notified
each time the scrollbar's model changes. Adjustment events are
provided for backwards compatibility with java.awt.Scrollbar.
Note that the AdjustmentEvents type property will always have a
placeholder value of AdjustmentEvent.TRACK because all changes
to a BoundedRangeModels value are considered equivalent. To change
the value of a BoundedRangeModel one just sets its value property,
i.e. model.setValue(123). No information about the origin of the
change, e.g. it's a block decrement, is provided. We don't try
fabricate the origin of the change here.
listenerList.add(AdjustmentListener.class, l);
|
private void | checkOrientation(int orientation)
switch (orientation) {
case VERTICAL:
case HORIZONTAL:
break;
default:
throw new IllegalArgumentException("orientation must be one of: VERTICAL, HORIZONTAL");
}
|
protected void | fireAdjustmentValueChanged(int id, int type, int value)Notify listeners that the scrollbar's model has changed.
fireAdjustmentValueChanged(id, type, value, getValueIsAdjusting());
|
private void | fireAdjustmentValueChanged(int id, int type, int value, boolean isAdjusting)Notify listeners that the scrollbar's model has changed.
Object[] listeners = listenerList.getListenerList();
AdjustmentEvent e = null;
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i]==AdjustmentListener.class) {
if (e == null) {
e = new AdjustmentEvent(this, id, type, value, isAdjusting);
}
((AdjustmentListener)listeners[i+1]).adjustmentValueChanged(e);
}
}
|
public javax.accessibility.AccessibleContext | getAccessibleContext()Gets the AccessibleContext associated with this JScrollBar.
For JScrollBar, the AccessibleContext takes the form of an
AccessibleJScrollBar.
A new AccessibleJScrollBar instance is created if necessary.
if (accessibleContext == null) {
accessibleContext = new AccessibleJScrollBar();
}
return accessibleContext;
|
public java.awt.event.AdjustmentListener[] | getAdjustmentListeners()Returns an array of all the AdjustmentListener s added
to this JScrollBar with addAdjustmentListener().
return (AdjustmentListener[])listenerList.getListeners(
AdjustmentListener.class);
|
public int | getBlockIncrement(int direction)Returns the amount to change the scrollbar's value by,
given a block (usually "page") up/down request. A ScrollBarUI
implementation typically calls this method when the user clicks
above or below the scrollbar "knob" to change the value
up or down by large amount. Subclasses my override this
method to compute a value, e.g. the change required to scroll
up or down one paragraph in a text document.
The JScrollPane component creates scrollbars (by default)
that override this method and delegate to the viewports
Scrollable view, if it has one. The Scrollable interface
provides a more specialized version of this method.
return blockIncrement;
|
public int | getBlockIncrement()For backwards compatibility with java.awt.Scrollbar.
return blockIncrement;
|
public int | getMaximum()The maximum value of the scrollbar is maximum - extent.
return getModel().getMaximum();
|
public java.awt.Dimension | getMaximumSize()The scrollbar is flexible along it's scrolling axis and
rigid along the other axis.
Dimension pref = getPreferredSize();
if (getOrientation() == VERTICAL) {
return new Dimension(pref.width, Short.MAX_VALUE);
} else {
return new Dimension(Short.MAX_VALUE, pref.height);
}
|
public int | getMinimum()Returns the minimum value supported by the scrollbar
(usually zero).
return getModel().getMinimum();
|
public java.awt.Dimension | getMinimumSize()The scrollbar is flexible along it's scrolling axis and
rigid along the other axis.
Dimension pref = getPreferredSize();
if (orientation == VERTICAL) {
return new Dimension(pref.width, 5);
} else {
return new Dimension(5, pref.height);
}
|
public javax.swing.BoundedRangeModel | getModel()Returns data model that handles the scrollbar's four
fundamental properties: minimum, maximum, value, extent.
return model;
|
public int | getOrientation()Returns the component's orientation (horizontal or vertical).
return orientation;
|
public javax.swing.plaf.ScrollBarUI | getUI()Returns the delegate that implements the look and feel for
this component.
return (ScrollBarUI)ui;
|
public java.lang.String | getUIClassID()Returns the name of the LookAndFeel class for this component.
return uiClassID;
|
public int | getUnitIncrement(int direction)Returns the amount to change the scrollbar's value by,
given a unit up/down request. A ScrollBarUI implementation
typically calls this method when the user clicks on a scrollbar
up/down arrow and uses the result to update the scrollbar's
value. Subclasses my override this method to compute
a value, e.g. the change required to scroll up or down one
(variable height) line text or one row in a table.
The JScrollPane component creates scrollbars (by default)
that override this method and delegate to the viewports
Scrollable view, if it has one. The Scrollable interface
provides a more specialized version of this method.
return unitIncrement;
|
public int | getUnitIncrement()For backwards compatibility with java.awt.Scrollbar.
return unitIncrement;
|
public int | getValue()Returns the scrollbar's value.
return getModel().getValue();
|
public boolean | getValueIsAdjusting()True if the scrollbar knob is being dragged.
return getModel().getValueIsAdjusting();
|
public int | getVisibleAmount()Returns the scrollbar's extent, aka its "visibleAmount". In many
scrollbar look and feel implementations the size of the
scrollbar "knob" or "thumb" is proportional to the extent.
return getModel().getExtent();
|
protected java.lang.String | paramString()Returns a string representation of this JScrollBar. This method
is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not
be null .
String orientationString = (orientation == HORIZONTAL ?
"HORIZONTAL" : "VERTICAL");
return super.paramString() +
",blockIncrement=" + blockIncrement +
",orientation=" + orientationString +
",unitIncrement=" + unitIncrement;
|
public void | removeAdjustmentListener(java.awt.event.AdjustmentListener l)Removes an AdjustmentEvent listener.
listenerList.remove(AdjustmentListener.class, l);
|
public void | setBlockIncrement(int blockIncrement)Sets the blockIncrement property.
Note, that if the argument is equal to the value of Integer.MIN_VALUE,
the most look and feels will not provide the scrolling to the right/down.
int oldValue = this.blockIncrement;
this.blockIncrement = blockIncrement;
firePropertyChange("blockIncrement", oldValue, blockIncrement);
|
public void | setEnabled(boolean x)Enables the component so that the knob position can be changed.
When the disabled, the knob position cannot be changed.
super.setEnabled(x);
Component[] children = getComponents();
for(int i = 0; i < children.length; i++) {
children[i].setEnabled(x);
}
|
public void | setMaximum(int maximum)Sets the model's maximum property. Note that the scrollbar's value
can only be set to maximum - extent.
getModel().setMaximum(maximum);
|
public void | setMinimum(int minimum)Sets the model's minimum property.
getModel().setMinimum(minimum);
|
public void | setModel(javax.swing.BoundedRangeModel newModel)Sets the model that handles the scrollbar's four
fundamental properties: minimum, maximum, value, extent.
Integer oldValue = null;
BoundedRangeModel oldModel = model;
if (model != null) {
model.removeChangeListener(fwdAdjustmentEvents);
oldValue = new Integer(model.getValue());
}
model = newModel;
if (model != null) {
model.addChangeListener(fwdAdjustmentEvents);
}
firePropertyChange("model", oldModel, model);
if (accessibleContext != null) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
oldValue, new Integer(model.getValue()));
}
|
public void | setOrientation(int orientation)Set the scrollbar's orientation to either VERTICAL or
HORIZONTAL.
checkOrientation(orientation);
int oldValue = this.orientation;
this.orientation = orientation;
firePropertyChange("orientation", oldValue, orientation);
if ((oldValue != orientation) && (accessibleContext != null)) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
((oldValue == VERTICAL)
? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL),
((orientation == VERTICAL)
? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL));
}
if (orientation != oldValue) {
revalidate();
}
|
public void | setUI(javax.swing.plaf.ScrollBarUI ui)Sets the L&F object that renders this component.
super.setUI(ui);
|
public void | setUnitIncrement(int unitIncrement)Sets the unitIncrement property.
Note, that if the argument is equal to the value of Integer.MIN_VALUE,
the most look and feels will not provide the scrolling to the right/down.
int oldValue = this.unitIncrement;
this.unitIncrement = unitIncrement;
firePropertyChange("unitIncrement", oldValue, unitIncrement);
|
public void | setValue(int value)Sets the scrollbar's value. This method just forwards the value
to the model.
BoundedRangeModel m = getModel();
int oldValue = m.getValue();
m.setValue(value);
if (accessibleContext != null) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
new Integer(oldValue),
new Integer(m.getValue()));
}
|
public void | setValueIsAdjusting(boolean b)Sets the model's valueIsAdjusting property. Scrollbar look and
feel implementations should set this property to true when
a knob drag begins, and to false when the drag ends. The
scrollbar model will not generate ChangeEvents while
valueIsAdjusting is true.
BoundedRangeModel m = getModel();
boolean oldValue = m.getValueIsAdjusting();
m.setValueIsAdjusting(b);
if ((oldValue != b) && (accessibleContext != null)) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
((oldValue) ? AccessibleState.BUSY : null),
((b) ? AccessibleState.BUSY : null));
}
|
public void | setValues(int newValue, int newExtent, int newMin, int newMax)Sets the four BoundedRangeModel properties after forcing
the arguments to obey the usual constraints:
minimum <= value <= value+extent <= maximum
BoundedRangeModel m = getModel();
int oldValue = m.getValue();
m.setRangeProperties(newValue, newExtent, newMin, newMax, m.getValueIsAdjusting());
if (accessibleContext != null) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
new Integer(oldValue),
new Integer(m.getValue()));
}
|
public void | setVisibleAmount(int extent)Set the model's extent property.
getModel().setExtent(extent);
|
public void | updateUI()Overrides JComponent.updateUI .
setUI((ScrollBarUI)UIManager.getUI(this));
|
private void | writeObject(java.io.ObjectOutputStream s)See readObject() and writeObject() in JComponent for more
information about serialization in Swing.
s.defaultWriteObject();
if (getUIClassID().equals(uiClassID)) {
byte count = JComponent.getWriteObjCounter(this);
JComponent.setWriteObjCounter(this, --count);
if (count == 0 && ui != null) {
ui.installUI(this);
}
}
|