Java: What is the difference between block increment and unit increment and what are these values used for?

StackOverflow https://stackoverflow.com/questions/20103589

Question

What is the difference between block increment and unit increment and what are these two values used for?

These two fields/values are used by the Adjustable class. This class includes these four methods:

int getBlockIncrement();
int getUnitIncrement();
void setBlockIncrement(int b);
void setUnitIncrement(int u);

The JScrollBar class for example implements this Adjustable class. These two values effect the behaviour of this scroll bar.

So, what are these two values used for exactly? Also, how do these values affect the behaviour of the JScrollBar component.

Are these values different by default on different operating systems?

Was it helpful?

Solution

When working with JScrollBar you can actually scroll(move the knob of the scroll bar):

  1. by clicking the arrow button placed at the border of JScrollBar.
  2. by clicking on the track upon which the knob is moving.

    enter image description here

clicking on the button scrolls the visible area by a unit increment and the track scrolls the visible area by a block increment.

Are these values different by default on different operating systems?

The OS has nothing to do with these.

OTHER TIPS

From here:

Normally, the user changes the value of the scroll bar by making a gesture with the mouse. For example, the user can drag the scroll bar's bubble up and down, or click in the scroll bar's unit increment or block increment areas. Keyboard gestures can also be mapped to the scroll bar. By convention, the Page Up and Page Down keys are equivalent to clicking in the scroll bar's block increment and block decrement areas.

  • AdjustmentEvent.UNIT_DECREMENT is sent out when the user clicks in the right arrow of a horizontal scroll bar, or the bottom arrow of a vertical scroll bar, or makes the equivalent gesture from the keyboard.
  • AdjustmentEvent.BLOCK_INCREMENT is sent out when the user clicks in the track, to the left of the bubble on a horizontal scroll bar, or above the bubble on a vertical scroll bar. By convention, the Page Up key is equivalent, if the user is using a keyboard that defines a Page Up key.
  • AdjustmentEvent.BLOCK_DECREMENT is sent out when the user clicks in the track, to the right of the bubble on a horizontal scroll bar, or below the bubble on a vertical scroll bar. By convention, the Page Down key is equivalent, if the user is using a keyboard that defines a Page Down key.

Block Increment is for when you click an empty part of the scroll bar, and Unit Increment is for when you click a scroll bar arrow.

From here

However, to create a custom component to be used inside a scroll pane you may need to customize its scrolling behavior ??? specifically you might need to set the unit and block increments. For a text area, for example, scrolling one unit means scrolling by one line of text. A block increment typically scrolls an entire "page", or the size of the viewport. For more information, see Implementing a Scrolling-Savvy Client in the How to Use Scroll Panes page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top