From: Niki Roo Date: Tue, 28 Apr 2020 14:51:50 +0000 (+0200) Subject: UIUtils.scroll: allow horizontal only X-Git-Tag: fanfix-swing-1.1.0~47 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=058a92e486235437193ba870869e76244d9c8120;p=fanfix-swing.git UIUtils.scroll: allow horizontal only --- diff --git a/src/be/nikiroo/utils/ui/UIUtils.java b/src/be/nikiroo/utils/ui/UIUtils.java index 9f16aabe..5861d00f 100644 --- a/src/be/nikiroo/utils/ui/UIUtils.java +++ b/src/be/nikiroo/utils/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; } }