From 3af909c1d3ed9a36e85cf9049348240475c3c17f Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Tue, 28 Apr 2020 16:51:50 +0200 Subject: [PATCH] UIUtils.scroll: allow horizontal only --- ui/UIUtils.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/ui/UIUtils.java b/ui/UIUtils.java index 9f16aab..5861d00 100644 --- a/ui/UIUtils.java +++ b/ui/UIUtils.java @@ -178,12 +178,39 @@ public class UIUtils { * @return the {@link JScrollPane} */ static public JScrollPane scroll(JComponent pane, boolean allowHorizontal) { + return scroll(pane, allowHorizontal, true); + } + + /** + * Add a {@link JScrollPane} around the given panel and use a sensible (for + * me) increment for the mouse wheel. + * + * @param pane + * the panel to wrap in a {@link JScrollPane} + * @param allowHorizontal + * allow horizontal scrolling (not always desired) + * @param allowVertical + * allow vertical scrolling (usually yes, but sometimes you only + * want horizontal) + * + * @return the {@link JScrollPane} + */ + static public JScrollPane scroll(JComponent pane, boolean allowHorizontal, + boolean allowVertical) { JScrollPane scroll = new JScrollPane(pane); + scroll.getVerticalScrollBar().setUnitIncrement(16); + scroll.getHorizontalScrollBar().setUnitIncrement(16); + if (!allowHorizontal) { scroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); } + if (!allowVertical) { + scroll.setVerticalScrollBarPolicy( + JScrollPane.VERTICAL_SCROLLBAR_NEVER); + } + return scroll; } } -- 2.27.0