Java Utililty Methods JScrollBar

List of utility methods to do JScrollBar

Description

The list of methods to do JScrollBar are organized into topic(s).

Method

booleanisPaintRequiredFor(javax.swing.JScrollBar jScrollBar)
is Paint Required For
if (jScrollBar != null) {
    return (jScrollBar.getMinimum() != jScrollBar.getValue())
            || (jScrollBar.getMaximum() != jScrollBar.getVisibleAmount());
} else {
    return false;
voidscrollByBlock(JScrollBar scrollbar, int direction)
scroll By Block
int oldValue = scrollbar.getValue();
int blockIncrement = scrollbar.getBlockIncrement(direction);
int delta = blockIncrement * ((direction > 0) ? +1 : -1);
int newValue = oldValue + delta;
if (delta > 0 && newValue < oldValue) {
    newValue = scrollbar.getMaximum();
} else if (delta < 0 && newValue > oldValue) {
    newValue = scrollbar.getMinimum();
...
voidscrollByUnits(JScrollBar scrollbar, int direction, int units, boolean limitToBlock)
scroll By Units
int delta;
int limit = -1;
if (limitToBlock) {
    if (direction < 0) {
        limit = scrollbar.getValue() - scrollbar.getBlockIncrement(direction);
    } else {
        limit = scrollbar.getValue() + scrollbar.getBlockIncrement(direction);
for (int i = 0; i < units; i++) {
    if (direction > 0) {
        delta = scrollbar.getUnitIncrement(direction);
    } else {
        delta = -scrollbar.getUnitIncrement(direction);
    int oldValue = scrollbar.getValue();
    int newValue = oldValue + delta;
    if (delta > 0 && newValue < oldValue) {
        newValue = scrollbar.getMaximum();
    } else if (delta < 0 && newValue > oldValue) {
        newValue = scrollbar.getMinimum();
    if (oldValue == newValue) {
        break;
    if (limitToBlock && i > 0) {
        assert limit != -1;
        if ((direction < 0 && newValue < limit) || (direction > 0 && newValue > limit)) {
            break;
    scrollbar.setValue(newValue);