From: Niki Roo Date: Tue, 28 Apr 2020 14:51:50 +0000 (+0200) Subject: UIUtils.scroll: allow horizontal only X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=3af909c1d3ed9a36e85cf9049348240475c3c17f;p=nikiroo-utils.git UIUtils.scroll: allow horizontal only --- 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; } }