📄 scrollbar.java
字号:
/**
* Sets the minimum value of this scroll bar.
* <p>
* Normally, a program should change a scroll bar's minimum
* value only by calling <code>setValues</code>.
* The <code>setValues</code> method simultaneously
* and synchronously sets the minimum, maximum, visible amount,
* and value properties of a scroll bar, so that they are
* mutually consistent.
* @param newMinimum the new minimum value
* for this scroll bar.
* @see java.awt.Scrollbar#setValues
* @see java.awt.Scrollbar#setMaximum
* @since JDK1.1
*/
public void setMinimum(int newMinimum) {
/* Use setValues so that a consistent policy
* relating minimum, maximum, and value is enforced.
*/
setValues(value, visibleAmount, newMinimum, maximum);
}
/**
* Gets the maximum value of this scroll bar.
* @return the maximum value of this scroll bar.
* @see java.awt.Scrollbar#getValue
* @see java.awt.Scrollbar#getMinimum
* @since JDK1.0
*/
public int getMaximum() {
return maximum;
}
/**
* Sets the maximum value of this scroll bar.
* <p>
* Normally, a program should change a scroll bar's maximum
* value only by calling <code>setValues</code>.
* The <code>setValues</code> method simultaneously
* and synchronously sets the minimum, maximum, visible amount,
* and value properties of a scroll bar, so that they are
* mutually consistent.
* @param newMaximum the new maximum value
* for this scroll bar.
* @see java.awtScrollbar#setValues
* @see java.awtScrollbar#setMinimum
* @since JDK1.1
*/
public void setMaximum(int newMaximum) {
/* Use setValues so that a consistent policy
* relating minimum, maximum, and value is enforced.
*/
setValues(value, visibleAmount, minimum, newMaximum);
}
/**
* Gets the visible amount of this scroll bar.
* <p>
* The visible amount of a scroll bar is the range of
* values represented by the width of the scroll bar's
* bubble. It is used to determine the scroll bar's
* block increment.
* @return the visible amount of this scroll bar.
* @see java.awt.Scrollbar#setVisibleAmount
* @since JDK1.1
*/
public int getVisibleAmount() {
return getVisible();
}
/**
* @deprecated As of JDK version 1.1,
* replaced by <code>getVisibleAmount()</code>.
*/
public int getVisible() {
return visibleAmount;
}
/**
* Sets the visible amount of this scroll bar.
* <p>
* The visible amount of a scroll bar is the range of
* values represented by the width of the scroll bar's
* bubble. It is used to determine the scroll bar's
* block increment.
* <p>
* Normally, a program should change a scroll bar's
* value only by calling <code>setValues</code>.
* The <code>setValues</code> method simultaneously
* and synchronously sets the minimum, maximum, visible amount,
* and value properties of a scroll bar, so that they are
* mutually consistent.
* @param newAmount the amount visible per page.
* @see java.awt.Scrollbar#getVisibleAmount
* @see java.awt.Scrollbar#setValues
* @since JDK1.1
*/
public void setVisibleAmount(int newAmount) {
setValues(value, newAmount, minimum, maximum);
}
/**
* Sets the unit increment for this scroll bar.
* <p>
* The unit increment is the value that is added (subtracted)
* when the user activates the unit increment area of the
* scroll bar, generally through a mouse or keyboard gesture
* that the scroll bar receives as an adjustment event.
* @param v the amount by which to increment or decrement
* the scroll bar's value.
* @see java.awt.Scrollbar#getUnitIncrement
* @since JDK1.1
*/
public void setUnitIncrement(int v) {
setLineIncrement(v);
}
/**
* @deprecated As of JDK version 1.1,
* replaced by <code>setUnitIncrement(int)</code>.
*/
public synchronized void setLineIncrement(int v) {
lineIncrement = v;
ScrollbarPeer peer = (ScrollbarPeer)this.peer;
if (peer != null) {
peer.setLineIncrement(v);
}
}
/**
* Gets the unit increment for this scrollbar.
* <p>
* The unit increment is the value that is added (subtracted)
* when the user activates the unit increment area of the
* scroll bar, generally through a mouse or keyboard gesture
* that the scroll bar receives as an adjustment event.
* @return the unit increment of this scroll bar.
* @see java.awt.Scrollbar#setUnitIncrement
* @since JDK1.1
*/
public int getUnitIncrement() {
return getLineIncrement();
}
/**
* @deprecated As of JDK version 1.1,
* replaced by <code>getUnitIncrement()</code>.
*/
public int getLineIncrement() {
return lineIncrement;
}
/**
* Sets the block increment for this scroll bar.
* <p>
* The block increment is the value that is added (subtracted)
* when the user activates the block increment area of the
* scroll bar, generally through a mouse or keyboard gesture
* that the scroll bar receives as an adjustment event.
* @param v the amount by which to increment or decrement
* the scroll bar's value.
* @see java.awt.Scrollbar#getBlockIncrement
* @since JDK1.1
*/
public void setBlockIncrement(int v) {
setPageIncrement(v);
}
/**
* @deprecated As of JDK version 1.1,
* replaced by <code>setBlockIncrement()</code>.
*/
public synchronized void setPageIncrement(int v) {
pageIncrement = v;
ScrollbarPeer peer = (ScrollbarPeer)this.peer;
if (peer != null) {
peer.setPageIncrement(v);
}
}
/**
* Gets the block increment of this scroll bar.
* <p>
* The block increment is the value that is added (subtracted)
* when the user activates the block increment area of the
* scroll bar, generally through a mouse or keyboard gesture
* that the scroll bar receives as an adjustment event.
* @return the block increment of this scroll bar.
* @see java.awt.Scrollbar#setBlockIncrement
* @since JDK1.1
*/
public int getBlockIncrement() {
return getPageIncrement();
}
/**
* @deprecated As of JDK version 1.1,
* replaced by <code>getBlockIncrement()</code>.
*/
public int getPageIncrement() {
return pageIncrement;
}
/**
* Sets the values of four properties for this scroll bar.
* <p>
* This method simultaneously and synchronously sets the values
* of four scroll bar properties, assuring that the values of
* these properties are mutually consistent. It enforces the
* constraints that maximum cannot be less than minimum, and that
* value cannot be less than the minimum or greater than the maximum.
* @param value is the position in the current window.
* @param visible is the amount visible per page.
* @param minimum is the minimum value of the scroll bar.
* @param maximum is the maximum value of the scroll bar.
* @since JDK1.0
*/
public synchronized void setValues(int value, int visible, int minimum, int maximum) {
if (maximum <= minimum) {
maximum = minimum + 1;
}
if (visible > maximum - minimum) {
visible = maximum - minimum;
}
if (visible < 1) {
visible = 1;
}
if (value < minimum) {
value = minimum;
}
if (value > maximum - visible) {
value = maximum - visible;
}
this.value = value;
this.visibleAmount = visible;
this.minimum = minimum;
this.maximum = maximum;
ScrollbarPeer peer = (ScrollbarPeer)this.peer;
if (peer != null) {
peer.setValues(value, visibleAmount, minimum, maximum);
}
}
/**
* Adds the specified adjustment listener to receive instances of
* <code>AdjustmentEvent</code> from this scroll bar.
* @param l the adjustment listener.
* @see java.awt.event.AdjustmentEvent
* @see java.awt.event.AdjustmentListener
* @see java.awt.Scrollbar#removeAdjustmentListener
* @since JDK1.1
*/
public synchronized void addAdjustmentListener(AdjustmentListener l) {
adjustmentListener = AWTEventMulticaster.add(adjustmentListener, l);
newEventsOnly = true;
}
/**
* Removes the specified adjustment listener so that it no longer
* receives instances of <code>AdjustmentEvent</code> from this scroll bar.
* @param l the adjustment listener.
* @see java.awt.event.AdjustmentEvent
* @see java.awt.event.AdjustmentListener
* @see java.awt.Scrollbar#addAdjustmentListener
* @since JDK1.1
*/
public synchronized void removeAdjustmentListener(AdjustmentListener l) {
adjustmentListener = AWTEventMulticaster.remove(adjustmentListener, l);
}
// REMIND: remove when filtering is done at lower level
boolean eventEnabled(AWTEvent e) {
if (e.id == AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED) {
if ((eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0 ||
adjustmentListener != null) {
return true;
}
return false;
}
return super.eventEnabled(e);
}
/**
* Processes events on this scroll bar. If the event is an
* instance of <code>AdjustmentEvent</code>, it invokes the
* <code>processAdjustmentEvent</code> method.
* Otherwise, it invokes its superclass's
* <code>processEvent</code> method.
* @param e the event.
* @see java.awt.event.AdjustmentEvent
* @see java.awt.Scrollbar#processAdjustmentEvent
* @since JDK1.1
*/
protected void processEvent(AWTEvent e) {
if (e instanceof AdjustmentEvent) {
processAdjustmentEvent((AdjustmentEvent)e);
return;
}
super.processEvent(e);
}
/**
* Processes adjustment events occurring on this
* scrollbar by dispatching them to any registered
* <code>AdjustmentListener</code> objects.
* <p>
* This method is not called unless adjustment events are
* enabled for this component. Adjustment events are enabled
* when one of the following occurs:
* <p><ul>
* <li>An <code>AdjustmentListener</code> object is registered
* via <code>addAdjustmentListener</code>.
* <li>Adjustment events are enabled via <code>enableEvents</code>.
* </ul><p>
* @param e the adjustment event.
* @see java.awt.event.AdjustmentEvent
* @see java.awt.event.AdjustmentListener
* @see java.awt.Scrollbar#addAdjustmentListener
* @see java.awt.Component#enableEvents
* @since JDK1.1
*/
protected void processAdjustmentEvent(AdjustmentEvent e) {
if (adjustmentListener != null) {
adjustmentListener.adjustmentValueChanged(e);
}
}
/**
* Returns the parameter string representing the state of
* this scroll bar. This string is useful for debugging.
* @return the parameter string of this scroll bar.
* @since JDK1.0
*/
protected String paramString() {
return super.paramString() +
",val=" + value +
",vis=" + visibleAmount +
",min=" + minimum +
",max=" + maximum +
((orientation == VERTICAL) ? ",vert" : ",horz");
}
/* Serialization support.
*/
private int scrollbarSerializedDataVersion = 1;
private void writeObject(ObjectOutputStream s)
throws IOException
{
s.defaultWriteObject();
AWTEventMulticaster.save(s, adjustmentListenerK, adjustmentListener);
s.writeObject(null);
}
private void readObject(ObjectInputStream s)
throws ClassNotFoundException, IOException
{
s.defaultReadObject();
Object keyOrNull;
while(null != (keyOrNull = s.readObject())) {
String key = ((String)keyOrNull).intern();
if (adjustmentListenerK == key)
addAdjustmentListener((AdjustmentListener)(s.readObject()));
else // skip value for unrecognized key
s.readObject();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -