List of usage examples for javax.swing JScrollBar getUnitIncrement
public int getUnitIncrement(int direction)
From source file:Main.java
/** * Scrolls the given component by its unit or block increment in the given direction (actually a scale factor, so use +1 or -1). * Useful for implementing behavior like in Apple's Mail where page up/page down in the list cause scrolling in the text. *///from w w w . ja v a2s .co m public static void scroll(JComponent c, boolean byBlock, int direction) { JScrollPane scrollPane = (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, c); JScrollBar scrollBar = scrollPane.getVerticalScrollBar(); int increment = byBlock ? scrollBar.getBlockIncrement(direction) : scrollBar.getUnitIncrement(direction); int newValue = scrollBar.getValue() + direction * increment; newValue = Math.min(newValue, scrollBar.getMaximum()); newValue = Math.max(newValue, scrollBar.getMinimum()); scrollBar.setValue(newValue); }
From source file:EditorDropTarget4.java
public void autoscroll(Point location) { JScrollPane scroller = (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, this); if (scroller != null) { JScrollBar hBar = scroller.getHorizontalScrollBar(); JScrollBar vBar = scroller.getVerticalScrollBar(); Rectangle r = getVisibleRect(); if (location.x <= r.x + scrollInsets.left) { // Need to scroll left hBar.setValue(hBar.getValue() - hBar.getUnitIncrement(-1)); }/*from ww w .j a v a 2 s. c o m*/ if (location.y <= r.y + scrollInsets.top) { // Need to scroll up vBar.setValue(vBar.getValue() - vBar.getUnitIncrement(-1)); } if (location.x >= r.x + r.width - scrollInsets.right) { // Need to scroll right hBar.setValue(hBar.getValue() + hBar.getUnitIncrement(1)); } if (location.y >= r.y + r.height - scrollInsets.bottom) { // Need to scroll down vBar.setValue(vBar.getValue() + vBar.getUnitIncrement(1)); } } }
From source file:net.sf.jabref.gui.maintable.MainTable.java
public void scrollTo(int y) { JScrollBar scb = pane.getVerticalScrollBar(); scb.setValue(y * scb.getUnitIncrement(1)); }