public class SmartScroller
extends java.lang.Object
implements java.awt.event.AdjustmentListener
Rob, if you somehow ever get wind of your class being used here: Thank you, thank you, thank
you, thank you, thank you so very much! You seriously made my day here.
Rob, you rule.
The SmartScroller will attempt to keep the viewport positioned based on
the users interaction
with the scrollbar. The normal behaviour is to keep
the viewport positioned to see new data
as it is dynamically added.
Assuming vertical scrolling and data is added to the bottom:
- when the viewport is at the bottom and new data is added,
then automatically scroll the
viewport to the bottom
- when the viewport is not at the bottom and new data is added,
then do nothing with the viewport
Assuming vertical scrolling and data is added to the top:
- when the viewport is at the top and new data is added,
then do nothing with the
viewport
- when the viewport is not at the top and new data is added, then adjust
the
viewport to the relative position it was at before the data was added
Similar logic would apply for horizontal scrolling.
| Modifier and Type | Field and Description |
|---|---|
static int |
END |
static int |
HORIZONTAL |
static int |
START |
static int |
VERTICAL |
| Constructor and Description |
|---|
SmartScroller(javax.swing.JScrollPane scrollPane)
Convenience constructor.
Scroll direction is VERTICAL and viewport position is at the END. |
SmartScroller(javax.swing.JScrollPane scrollPane,
int viewportPosition)
Convenience constructor.
Scroll direction is VERTICAL. |
SmartScroller(javax.swing.JScrollPane scrollPane,
int scrollDirection,
int viewportPosition)
Specify how the SmartScroller will function.
|
| Modifier and Type | Method and Description |
|---|---|
void |
adjustmentValueChanged(java.awt.event.AdjustmentEvent e) |
public static final int HORIZONTAL
public static final int VERTICAL
public static final int START
public static final int END
public SmartScroller(javax.swing.JScrollPane scrollPane)
scrollPane - the scroll pane to monitorpublic SmartScroller(javax.swing.JScrollPane scrollPane,
int viewportPosition)
scrollPane - the scroll pane to monitorviewportPosition - valid values are START and ENDpublic SmartScroller(javax.swing.JScrollPane scrollPane,
int scrollDirection,
int viewportPosition)
scrollPane - the scroll pane to monitorscrollDirection - indicates which JScrollBar to monitor. Valid values are HORIZONTAL and
VERTICAL.viewportPosition - indicates where the viewport will normally be positioned as data is
added. Valid values are START and END