Java Code Examples for javax.swing.JScrollBar#setUnitIncrement()

The following examples show how to use javax.swing.JScrollBar#setUnitIncrement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DockableMenu.java    From rapidminer-studio with GNU Affero General Public License v3.0 7 votes vote down vote up
/**
 * Ensures that the correct maximum height is set for the popup menu and sets the scroll increment.
 * Will only take effect with the first item added. Makes sure the height is set to {@link #MAX_SHOWN_ITEMS}*itemHeight.
 *
 * @since 8.2
 */
private void ensurePopupHeight() {
	JPopupMenu popupMenu = getPopupMenu();
	if (popupMenu.getSubElements().length != 1 || !(popupMenu instanceof ScrollableJPopupMenu)) {
		return;
	}
	ScrollableJPopupMenu scrollablePopup = (ScrollableJPopupMenu) popupMenu;
	int itemHeight = scrollablePopup.getComponentsInsideScrollpane()[0].getPreferredSize().height;
	int maxHeight = MAX_SHOWN_ITEMS * itemHeight;
	maxHeight = Math.min(maxHeight, ScrollableJPopupMenu.SIZE_HUGE);
	scrollablePopup.setMaxHeight(maxHeight);
	JScrollPane scrollPane = scrollablePopup.getScrollPane();
	JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
	verticalScrollBar.setUnitIncrement(itemHeight);
	verticalScrollBar.setBlockIncrement(maxHeight);
}
 
Example 2
Source File: DebuggingViewComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void adjustTreeScrollBar(int treeViewWidth) {
    DebugTreeView tView = getTreeView();
    if (tView == null) {
        scrollBarPanel.setVisible(false);
        return;
    }
    JViewport viewport = tView.getViewport();
    Point point = viewport.getViewPosition();
    if (point.y < 0) {
        viewport.setViewPosition(new Point(point.x, 0));
    }
    Dimension viewSize = viewport.getExtentSize();
    Dimension treeSize = viewport.getViewSize();
    if (treeViewWidth < 0) {
        treeViewWidth = treeSize.width;
    }
    int unitHeight = tView.getUnitHeight();
    if (unitHeight > 0) {
        JScrollBar sbar = mainScrollPane.getVerticalScrollBar();
        if (sbar.getUnitIncrement() != unitHeight) {
            sbar.setUnitIncrement(unitHeight);
        }
    }
    if (treeViewWidth <= viewSize.width) {
        scrollBarPanel.setVisible(false);
    } else {
        treeScrollBar.setMaximum(treeViewWidth);
        treeScrollBar.setVisibleAmount(viewSize.width);
        if (unitHeight > 0) {
            treeScrollBar.setUnitIncrement(unitHeight / 2);
        }
        treeScrollBar.setBlockIncrement(viewSize.width);
        scrollBarPanel.setVisible(true);
    } // else
}
 
Example 3
Source File: ScrollView.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Create a bare view pane.
 * Other related entities, such as view, pixel monitor or zoom, can be added later
 * programmatically via setXXX() methods).
 * <p>
 * The increment related to mouse wheel movement can be adapted via the 'unitIncrement' class
 * constant.
 */
public ScrollView ()
{
    JScrollBar vertical = component.getVerticalScrollBar();
    vertical.setUnitIncrement(constants.unitIncrement.getValue());

    JScrollBar horizontal = component.getHorizontalScrollBar();
    horizontal.setUnitIncrement(constants.unitIncrement.getValue());

    bindKeys(component);
}
 
Example 4
Source File: CustomScrollBarUI.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static ComponentUI createUI(JComponent c)
{
	JScrollBar bar = (JScrollBar) c;
	bar.setUnitIncrement(16);
	bar.setPreferredSize(new Dimension(7, 0));
	return new CustomScrollBarUI();
}
 
Example 5
Source File: LogViewer.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
public LogScrollPane(Component aView) {

            super(aView);

            final JScrollBar vscroll = getVerticalScrollBar();
            vscroll.setUnitIncrement(INCREMENT);
            vscroll.setBlockIncrement(INCREMENT);
            vscroll.addAdjustmentListener(e -> e.getAdjustable().setValue(e.getAdjustable().getMaximum()));

            setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
            setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);

            setBorder(BorderFactory.createEmptyBorder());
            getViewport().setOpaque(false);
        }
 
Example 6
Source File: ScrollView.java    From libreveris with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Create a bare view pane.
 * Other related entities, such as view, pixel monitor or zoom, can be
 * added later programmatically via setXXX() methods).
 * <p>The increment related to mouse wheel movement can be adapted via the
 * unitIncrement class constant.
 */
public ScrollView ()
{
    JScrollBar vertical = component.getVerticalScrollBar();
    vertical.setUnitIncrement(constants.unitIncrement.getValue());
}