Ignore:
Timestamp:
2016-02-10T20:47:11+01:00 (4 years ago)
Author:
bastiK
Message:

see #12507 - fix mouse wheel scrolling at some places

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java

    r9576 r9778  
    3737import javax.swing.JPanel;
    3838import javax.swing.JScrollPane;
     39import javax.swing.Scrollable;
    3940import javax.swing.SwingUtilities;
    4041import javax.swing.Timer;
     
    341342
    342343    /**
     344     * Set the default unit increment for a {@code JScrollPane}.
     345     *
     346     * This fixes slow mouse wheel scrolling when the content of the {@code JScrollPane}
     347     * is a {@code JPanel} or other component that does not implement the {@link Scrollable}
     348     * interface.
     349     * The default unit increment is 1 pixel. Multiplied by the number of unit increments
     350     * per mouse wheel "click" (platform dependent, usually 3), this makes a very
     351     * sluggish mouse wheel experience.
     352     * This methods sets the unit increment to a larger, more reasonable value.
     353     * @param sp the scroll pane
     354     * @return the scroll pane (same object) with fixed unit increment
     355     * @throws IllegalArgumentException if the component inside of the scroll pane
     356     * implements the {@code Scrollable} interface ({@code JTree}, {@code JLayer},
     357     * {@code JList}, {@code JTextComponent} and {@code JTable})
     358     */
     359    public static JScrollPane setDefaultIncrement(JScrollPane sp) {
     360        if (sp.getViewport().getView() instanceof Scrollable) {
     361            throw new IllegalArgumentException();
     362        }
     363        sp.getVerticalScrollBar().setUnitIncrement(10);
     364        sp.getHorizontalScrollBar().setUnitIncrement(10);
     365        return sp;
     366    }
     367
     368    /**
    343369     * Returns extended modifier key used as the appropriate accelerator key for menu shortcuts.
    344370     * It is advised everywhere to use {@link Toolkit#getMenuShortcutKeyMask()} to get the cross-platform modifier, but:
Note: See TracChangeset for help on using the changeset viewer.