Index: trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java	(revision 7459)
+++ trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java	(revision 7463)
@@ -54,7 +54,4 @@
     }
 
-    /* (non-Javadoc)
-     * @see org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask#download(boolean, org.openstreetmap.josm.data.Bounds, org.openstreetmap.josm.gui.progress.ProgressMonitor)
-     */
     @Override
     public Future<?> download(boolean newLayer, Bounds downloadArea,
@@ -63,7 +60,4 @@
     }
 
-    /* (non-Javadoc)
-     * @see org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask#loadUrl(boolean, java.lang.String, org.openstreetmap.josm.gui.progress.ProgressMonitor)
-     */
     @Override
     public Future<?> loadUrl(boolean new_layer, String url,
@@ -84,7 +78,4 @@
         }
 
-        /* (non-Javadoc)
-         * @see org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask.DownloadTask#parseDataSet()
-         */
         @Override
         protected DataSet parseDataSet() throws OsmTransferException {
@@ -92,7 +83,4 @@
         }
 
-        /* (non-Javadoc)
-         * @see org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask.DownloadTask#finish()
-         */
         @Override
         protected void finish() {
Index: trunk/src/org/openstreetmap/josm/actions/search/PushbackTokenizer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/search/PushbackTokenizer.java	(revision 7459)
+++ trunk/src/org/openstreetmap/josm/actions/search/PushbackTokenizer.java	(revision 7463)
@@ -32,7 +32,4 @@
         }
 
-        /* (non-Javadoc)
-         * @see java.lang.Object#toString()
-         */
         @Override
         public String toString() {
Index: trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java	(revision 7459)
+++ trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java	(revision 7463)
@@ -33,4 +33,5 @@
 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo;
 import org.openstreetmap.josm.data.imagery.Shape;
+import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
 import org.openstreetmap.josm.gui.layer.ImageryLayer;
 import org.openstreetmap.josm.gui.layer.Layer;
@@ -38,5 +39,10 @@
 import org.openstreetmap.josm.tools.ImageProvider;
 
-public class ImageryMenu extends JMenu implements MapView.LayerChangeListener {
+/**
+ * Imagery menu, holding entries for imagery preferences, offset actions and dynamic imagery entries
+ * depending on current maview coordinates.
+ * @since 3737
+ */
+public class ImageryMenu extends JMenu implements LayerChangeListener {
 
     private Action offsetAction = new JosmAction(
@@ -83,4 +89,8 @@
     private final MapRectifierWMSmenuAction rectaction = new MapRectifierWMSmenuAction();
 
+    /**
+     * Constructs a new {@code ImageryMenu}.
+     * @param subMenu submenu in that contains plugin-managed additional imagery layers
+     */
     public ImageryMenu(JMenu subMenu) {
         super(tr("Imagery"));
@@ -107,7 +117,5 @@
     private void setupMenuScroller() {
         if (!GraphicsEnvironment.isHeadless()) {
-            int menuItemHeight = singleOffset.getPreferredSize().height;
-            MenuScroller.setScrollerFor(this, 
-                    MenuScroller.computeScrollCount(this, menuItemHeight));
+            MenuScroller.setScrollerFor(this, 150, 2);
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/MainMenu.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/MainMenu.java	(revision 7459)
+++ trunk/src/org/openstreetmap/josm/gui/MainMenu.java	(revision 7463)
@@ -570,7 +570,5 @@
         final JMenu menu = new JMenu(tr(name));
         if (!GraphicsEnvironment.isHeadless()) {
-            int menuItemHeight = new JMenu().add(newAction).getPreferredSize().height;
-            MenuScroller.setScrollerFor(menu,
-                    MenuScroller.computeScrollCount(menu, menuItemHeight));
+            MenuScroller.setScrollerFor(menu);
         }
         return addMenu(menu, name, mnemonicKey, position, relativeHelpTopic);
Index: trunk/src/org/openstreetmap/josm/gui/MenuScroller.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/MenuScroller.java	(revision 7459)
+++ trunk/src/org/openstreetmap/josm/gui/MenuScroller.java	(revision 7463)
@@ -2,4 +2,5 @@
  * MenuScroller.java    1.5.0 04/02/12
  * License: use / modify without restrictions (see https://tips4java.wordpress.com/about/)
+ * Heavily modified for JOSM needs => drop unused features and replace static scrollcount approach by dynamic behaviour
  */
 package org.openstreetmap.josm.gui;
@@ -9,18 +10,16 @@
 import java.awt.Dimension;
 import java.awt.Graphics;
-import java.awt.GraphicsConfiguration;
-import java.awt.Insets;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.MouseWheelEvent;
 import java.awt.event.MouseWheelListener;
+import java.util.Arrays;
 
 import javax.swing.Icon;
-import javax.swing.JComponent;
+import javax.swing.JFrame;
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
 import javax.swing.JPopupMenu;
 import javax.swing.JSeparator;
-import javax.swing.MenuSelectionManager;
 import javax.swing.Timer;
 import javax.swing.event.ChangeEvent;
@@ -30,13 +29,14 @@
 
 import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.tools.WindowGeometry;
 
 /**
  * A class that provides scrolling capabilities to a long menu dropdown or
  * popup menu. A number of items can optionally be frozen at the top of the menu.
- * <P>
- * <B>Implementation note:</B>  The default number of items to display
- * at a time is 15, and the default scrolling interval is 150 milliseconds.
- * <P>
+ * <p>
+ * <b>Implementation note:</B>  The default scrolling interval is 150 milliseconds.
+ * <p>
  * @author Darryl, https://tips4java.wordpress.com/2009/02/01/menu-scroller/
+ * @since 4593
  */
 public class MenuScroller {
@@ -48,39 +48,49 @@
     private final MenuScrollListener menuListener = new MenuScrollListener();
     private final MouseWheelListener mouseWheelListener = new MouseScrollListener();
-    private int scrollCount;
     private int interval;
     private int topFixedCount;
     private int firstIndex = 0;
-    private int keepVisibleIndex = -1;
 
     private static final int ARROW_ICON_HEIGHT = 10;
 
-    /**
-     * Computes the number of items to display at once for the given component and a given item height.
-     * @param comp The menu
-     * @param itemHeight Average item height
-     * @return the number of items to display at once
-     * @since 7291
-     */
-    public static int computeScrollCount(JComponent comp, int itemHeight) {
+    private int computeScrollCount(int startIndex) {
         int result = 15;
-        if (comp != null && itemHeight > 0) {
+        if (menu != null) {
             // Compute max height of current screen
-            int maxHeight = 0;
-            GraphicsConfiguration gc = comp.getGraphicsConfiguration();
-            if (gc == null && Main.parent != null) {
-                gc = Main.parent.getGraphicsConfiguration();
-            }
-            if (gc != null) {
-                // Max displayable height (max screen height - vertical insets)
-                Insets insets = comp.getToolkit().getScreenInsets(gc);
-                maxHeight = gc.getBounds().height - insets.top - insets.bottom;
-            }
-
-            // Remove height of our two arrow icons + 2 pixels each for borders (arbitrary value)
-            maxHeight -= 2*(ARROW_ICON_HEIGHT+2);
-
-            if (maxHeight > 0) {
-                result = (maxHeight/itemHeight)-1;
+            int maxHeight = WindowGeometry.getMaxDimensionOnScreen(menu).height - ((JFrame)Main.parent).getInsets().top;
+
+            // Remove top fixed part height
+            if (topFixedCount > 0) {
+                for (int i = 0; i < topFixedCount; i++) {
+                    maxHeight -= menuItems[i].getPreferredSize().height;
+                }
+                maxHeight -= new JSeparator().getPreferredSize().height;
+            }
+
+            // Remove height of our two arrow items + insets
+            maxHeight -= menu.getInsets().top;
+            maxHeight -= upItem.getPreferredSize().height;
+            maxHeight -= downItem.getPreferredSize().height;
+            maxHeight -= menu.getInsets().bottom;
+
+            // Compute scroll count
+            result = 0;
+            int height = 0;
+            for (int i = startIndex; i < menuItems.length && height <= maxHeight; i++, result++) {
+                height += menuItems[i].getPreferredSize().height;
+            }
+
+            if (height > maxHeight) {
+                // Remove extra item from count
+                result--;
+            } else {
+                // Increase scroll count to take into account upper items that will be displayed
+                // after firstIndex is updated
+                for (int i=startIndex-1; i >= 0 && height <= maxHeight; i--, result++) {
+                    height += menuItems[i].getPreferredSize().height;
+                }
+                if (height > maxHeight) {
+                    result--;
+                }
             }
         }
@@ -89,6 +99,5 @@
 
     /**
-     * Registers a menu to be scrolled with the default number of items to
-     * display at a time and the default scrolling interval.
+     * Registers a menu to be scrolled with the default scrolling interval.
      *
      * @param menu the menu
@@ -100,6 +109,5 @@
 
     /**
-     * Registers a popup menu to be scrolled with the default number of items to
-     * display at a time and the default scrolling interval.
+     * Registers a popup menu to be scrolled with the default scrolling interval.
      *
      * @param menu the popup menu
@@ -111,64 +119,34 @@
 
     /**
-     * Registers a menu to be scrolled with the default number of items to
-     * display at a time and the specified scrolling interval.
+     * Registers a menu to be scrolled, with the specified scrolling interval.
      *
      * @param menu the menu
-     * @param scrollCount the number of items to display at a time
-     * @return the MenuScroller
-     * @throws IllegalArgumentException if scrollCount is 0 or negative
-     */
-    public static MenuScroller setScrollerFor(JMenu menu, int scrollCount) {
-        return new MenuScroller(menu, scrollCount);
-    }
-
-    /**
-     * Registers a popup menu to be scrolled with the default number of items to
-     * display at a time and the specified scrolling interval.
-     *
-     * @param menu the popup menu
-     * @param scrollCount the number of items to display at a time
-     * @return the MenuScroller
-     * @throws IllegalArgumentException if scrollCount is 0 or negative
-     */
-    public static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount) {
-        return new MenuScroller(menu, scrollCount);
-    }
-
-    /**
-     * Registers a menu to be scrolled, with the specified number of items to
-     * display at a time and the specified scrolling interval.
-     *
-     * @param menu the menu
-     * @param scrollCount the number of items to be displayed at a time
      * @param interval the scroll interval, in milliseconds
      * @return the MenuScroller
      * @throws IllegalArgumentException if scrollCount or interval is 0 or negative
-     */
-    public static MenuScroller setScrollerFor(JMenu menu, int scrollCount, int interval) {
-        return new MenuScroller(menu, scrollCount, interval);
-    }
-
-    /**
-     * Registers a popup menu to be scrolled, with the specified number of items to
-     * display at a time and the specified scrolling interval.
+     * @since 7463
+     */
+    public static MenuScroller setScrollerFor(JMenu menu, int interval) {
+        return new MenuScroller(menu, interval);
+    }
+
+    /**
+     * Registers a popup menu to be scrolled, with the specified scrolling interval.
      *
      * @param menu the popup menu
-     * @param scrollCount the number of items to be displayed at a time
      * @param interval the scroll interval, in milliseconds
      * @return the MenuScroller
      * @throws IllegalArgumentException if scrollCount or interval is 0 or negative
-     */
-    public static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount, int interval) {
-        return new MenuScroller(menu, scrollCount, interval);
-    }
-
-    /**
-     * Registers a menu to be scrolled, with the specified number of items
-     * to display in the scrolling region, the specified scrolling interval,
+     * @since 7463
+     */
+    public static MenuScroller setScrollerFor(JPopupMenu menu, int interval) {
+        return new MenuScroller(menu, interval);
+    }
+
+    /**
+     * Registers a menu to be scrolled, with the specified scrolling interval,
      * and the specified numbers of items fixed at the top of the menu.
      *
      * @param menu the menu
-     * @param scrollCount the number of items to display in the scrolling portion
      * @param interval the scroll interval, in milliseconds
      * @param topFixedCount the number of items to fix at the top.  May be 0.
@@ -176,137 +154,105 @@
      * negative or if topFixedCount is negative
      * @return the MenuScroller
-     */
-    public static MenuScroller setScrollerFor(JMenu menu, int scrollCount, int interval,
-            int topFixedCount) {
-        return new MenuScroller(menu, scrollCount, interval, topFixedCount);
-    }
-
-    /**
-     * Registers a popup menu to be scrolled, with the specified number of items
-     * to display in the scrolling region, the specified scrolling interval,
+     * @since 7463
+     */
+    public static MenuScroller setScrollerFor(JMenu menu, int interval, int topFixedCount) {
+        return new MenuScroller(menu, interval, topFixedCount);
+    }
+
+    /**
+     * Registers a popup menu to be scrolled, with the specified scrolling interval,
      * and the specified numbers of items fixed at the top of the popup menu.
      *
      * @param menu the popup menu
-     * @param scrollCount the number of items to display in the scrolling portion
+     * @param interval the scroll interval, in milliseconds
+     * @param topFixedCount the number of items to fix at the top. May be 0
+     * @throws IllegalArgumentException if scrollCount or interval is 0 or
+     * negative or if topFixedCount is negative
+     * @return the MenuScroller
+     * @since 7463
+     */
+    public static MenuScroller setScrollerFor(JPopupMenu menu, int interval, int topFixedCount) {
+        return new MenuScroller(menu, interval, topFixedCount);
+    }
+
+    /**
+     * Constructs a <code>MenuScroller</code> that scrolls a menu with the
+     * default scrolling interval.
+     *
+     * @param menu the menu
+     * @throws IllegalArgumentException if scrollCount is 0 or negative
+     */
+    public MenuScroller(JMenu menu) {
+        this(menu, 150);
+    }
+
+    /**
+     * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
+     * default scrolling interval.
+     *
+     * @param menu the popup menu
+     * @throws IllegalArgumentException if scrollCount is 0 or negative
+     */
+    public MenuScroller(JPopupMenu menu) {
+        this(menu, 150);
+    }
+
+    /**
+     * Constructs a <code>MenuScroller</code> that scrolls a menu with the
+     * specified scrolling interval.
+     *
+     * @param menu the menu
+     * @param interval the scroll interval, in milliseconds
+     * @throws IllegalArgumentException if scrollCount or interval is 0 or negative
+     * @since 7463
+     */
+    public MenuScroller(JMenu menu, int interval) {
+        this(menu, interval, 0);
+    }
+
+    /**
+     * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
+     * specified scrolling interval.
+     *
+     * @param menu the popup menu
+     * @param interval the scroll interval, in milliseconds
+     * @throws IllegalArgumentException if scrollCount or interval is 0 or negative
+     * @since 7463
+     */
+    public MenuScroller(JPopupMenu menu, int interval) {
+        this(menu, interval, 0);
+    }
+
+    /**
+     * Constructs a <code>MenuScroller</code> that scrolls a menu with the
+     * specified scrolling interval, and the specified numbers of items fixed at
+     * the top of the menu.
+     *
+     * @param menu the menu
      * @param interval the scroll interval, in milliseconds
      * @param topFixedCount the number of items to fix at the top.  May be 0
      * @throws IllegalArgumentException if scrollCount or interval is 0 or
      * negative or if topFixedCount is negative
-     * @return the MenuScroller
-     */
-    public static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount, int interval,
-            int topFixedCount) {
-        return new MenuScroller(menu, scrollCount, interval, topFixedCount);
-    }
-
-    /**
-     * Constructs a <code>MenuScroller</code> that scrolls a menu with the
-     * default number of items to display at a time, and default scrolling
-     * interval.
-     *
-     * @param menu the menu
-     */
-    public MenuScroller(JMenu menu) {
-        this(menu, computeScrollCount(menu, 30));
+     * @since 7463
+     */
+    public MenuScroller(JMenu menu, int interval, int topFixedCount) {
+        this(menu.getPopupMenu(), interval, topFixedCount);
     }
 
     /**
      * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
-     * default number of items to display at a time, and default scrolling
-     * interval.
+     * specified scrolling interval, and the specified numbers of items fixed at
+     * the top of the popup menu.
      *
      * @param menu the popup menu
-     */
-    public MenuScroller(JPopupMenu menu) {
-        this(menu, computeScrollCount(menu, 30));
-    }
-
-    /**
-     * Constructs a <code>MenuScroller</code> that scrolls a menu with the
-     * specified number of items to display at a time, and default scrolling
-     * interval.
-     *
-     * @param menu the menu
-     * @param scrollCount the number of items to display at a time
-     * @throws IllegalArgumentException if scrollCount is 0 or negative
-     */
-    public MenuScroller(JMenu menu, int scrollCount) {
-        this(menu, scrollCount, 150);
-    }
-
-    /**
-     * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
-     * specified number of items to display at a time, and default scrolling
-     * interval.
-     *
-     * @param menu the popup menu
-     * @param scrollCount the number of items to display at a time
-     * @throws IllegalArgumentException if scrollCount is 0 or negative
-     */
-    public MenuScroller(JPopupMenu menu, int scrollCount) {
-        this(menu, scrollCount, 150);
-    }
-
-    /**
-     * Constructs a <code>MenuScroller</code> that scrolls a menu with the
-     * specified number of items to display at a time, and specified scrolling
-     * interval.
-     *
-     * @param menu the menu
-     * @param scrollCount the number of items to display at a time
-     * @param interval the scroll interval, in milliseconds
-     * @throws IllegalArgumentException if scrollCount or interval is 0 or negative
-     */
-    public MenuScroller(JMenu menu, int scrollCount, int interval) {
-        this(menu, scrollCount, interval, 0);
-    }
-
-    /**
-     * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
-     * specified number of items to display at a time, and specified scrolling
-     * interval.
-     *
-     * @param menu the popup menu
-     * @param scrollCount the number of items to display at a time
-     * @param interval the scroll interval, in milliseconds
-     * @throws IllegalArgumentException if scrollCount or interval is 0 or negative
-     */
-    public MenuScroller(JPopupMenu menu, int scrollCount, int interval) {
-        this(menu, scrollCount, interval, 0);
-    }
-
-    /**
-     * Constructs a <code>MenuScroller</code> that scrolls a menu with the
-     * specified number of items to display in the scrolling region, the
-     * specified scrolling interval, and the specified numbers of items fixed at
-     * the top of the menu.
-     *
-     * @param menu the menu
-     * @param scrollCount the number of items to display in the scrolling portion
      * @param interval the scroll interval, in milliseconds
      * @param topFixedCount the number of items to fix at the top.  May be 0
      * @throws IllegalArgumentException if scrollCount or interval is 0 or
      * negative or if topFixedCount is negative
-     */
-    public MenuScroller(JMenu menu, int scrollCount, int interval, int topFixedCount) {
-        this(menu.getPopupMenu(), scrollCount, interval, topFixedCount);
-    }
-
-    /**
-     * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
-     * specified number of items to display in the scrolling region, the
-     * specified scrolling interval, and the specified numbers of items fixed at
-     * the top of the popup menu.
-     *
-     * @param menu the popup menu
-     * @param scrollCount the number of items to display in the scrolling portion
-     * @param interval the scroll interval, in milliseconds
-     * @param topFixedCount the number of items to fix at the top.  May be 0
-     * @throws IllegalArgumentException if scrollCount or interval is 0 or
-     * negative or if topFixedCount is negative
-     */
-    public MenuScroller(JPopupMenu menu, int scrollCount, int interval, int topFixedCount) {
-        if (scrollCount <= 0 || interval <= 0) {
-            throw new IllegalArgumentException("scrollCount and interval must be greater than 0");
+     * @since 7463
+     */
+    public MenuScroller(JPopupMenu menu, int interval, int topFixedCount) {
+        if (interval <= 0) {
+            throw new IllegalArgumentException("interval must be greater than 0");
         }
         if (topFixedCount < 0) {
@@ -316,5 +262,4 @@
         upItem = new MenuScrollItem(MenuIcon.UP, -1);
         downItem = new MenuScrollItem(MenuIcon.DOWN, +1);
-        setScrollCount(scrollCount);
         setInterval(interval);
         setTopFixedCount(topFixedCount);
@@ -347,27 +292,4 @@
         downItem.setInterval(interval);
         this.interval = interval;
-    }
-
-    /**
-     * Returns the number of items in the scrolling portion of the menu.
-     *
-     * @return the number of items to display at a time
-     */
-    public int getscrollCount() {
-        return scrollCount;
-    }
-
-    /**
-     * Sets the number of items in the scrolling portion of the menu.
-     *
-     * @param scrollCount the number of items to display at a time
-     * @throws IllegalArgumentException if scrollCount is 0 or negative
-     */
-    public void setScrollCount(int scrollCount) {
-        if (scrollCount <= 0) {
-            throw new IllegalArgumentException("scrollCount must be greater than 0");
-        }
-        this.scrollCount = scrollCount;
-        MenuSelectionManager.defaultManager().clearSelectedPath();
     }
 
@@ -393,33 +315,4 @@
         }
         this.topFixedCount = topFixedCount;
-    }
-
-    /**
-     * Scrolls the specified item into view each time the menu is opened.  Call this method with
-     * <code>null</code> to restore the default behavior, which is to show the menu as it last
-     * appeared.
-     *
-     * @param item the item to keep visible
-     * @see #keepVisible(int)
-     */
-    public void keepVisible(JMenuItem item) {
-        if (item == null) {
-            keepVisibleIndex = -1;
-        } else {
-            int index = menu.getComponentIndex(item);
-            keepVisibleIndex = index;
-        }
-    }
-
-    /**
-     * Scrolls the item at the specified index into view each time the menu is opened.  Call this
-     * method with <code>-1</code> to restore the default behavior, which is to show the menu as
-     * it last appeared.
-     *
-     * @param index the index of the item to keep visible
-     * @see #keepVisible(javax.swing.JMenuItem)
-     */
-    public void keepVisible(int index) {
-        keepVisibleIndex = index;
     }
 
@@ -453,35 +346,51 @@
         if (menuItems != null && menuItems.length > 0) {
 
-            int numOfNonSepItems = getNumberOfNonSeparatorItems(menuItems);
-
-            firstIndex = Math.max(topFixedCount, firstIndex);
-            firstIndex = Math.min(numOfNonSepItems - scrollCount, firstIndex);
-
-            upItem.setEnabled(firstIndex > topFixedCount);
-            downItem.setEnabled(firstIndex + scrollCount < numOfNonSepItems);
-
-            menu.removeAll();
-            for (int i = 0; i < topFixedCount; i++) {
-                menu.add(menuItems[i]);
-            }
-            if (topFixedCount > 0) {
-                menu.addSeparator();
-            }
-
-            menu.add(upItem);
-            for (int i = firstIndex; i < scrollCount + firstIndex; i++) {
-                menu.add(menuItems[i]);
-            }
-            menu.add(downItem);
-
-            int preferredWidth = 0;
+            int allItemsHeight = 0;
             for (Component item : menuItems) {
-                preferredWidth = Math.max(preferredWidth, item.getPreferredSize().width);
-            }
-            menu.setPreferredSize(new Dimension(preferredWidth, menu.getPreferredSize().height));
-
-            JComponent parent = (JComponent) upItem.getParent();
-            parent.revalidate();
-            parent.repaint();
+                allItemsHeight += item.getPreferredSize().height;
+            }
+
+            int allowedHeight = WindowGeometry.getMaxDimensionOnScreen(menu).height - ((JFrame)Main.parent).getInsets().top;
+
+            boolean mustSCroll = allItemsHeight > allowedHeight;
+
+            if (mustSCroll) {
+                firstIndex = Math.max(topFixedCount, firstIndex);
+                int scrollCount = computeScrollCount(firstIndex);
+                firstIndex = Math.min(menuItems.length - scrollCount, firstIndex);
+
+                upItem.setEnabled(firstIndex > topFixedCount);
+                downItem.setEnabled(firstIndex + scrollCount < menuItems.length);
+
+                menu.removeAll();
+                for (int i = 0; i < topFixedCount; i++) {
+                    menu.add(menuItems[i]);
+                }
+                if (topFixedCount > 0) {
+                    menu.addSeparator();
+                }
+
+                menu.add(upItem);
+                for (int i = firstIndex; i < scrollCount + firstIndex; i++) {
+                    menu.add(menuItems[i]);
+                }
+                menu.add(downItem);
+
+                int preferredWidth = 0;
+                for (Component item : menuItems) {
+                    preferredWidth = Math.max(preferredWidth, item.getPreferredSize().width);
+                }
+                menu.setPreferredSize(new Dimension(preferredWidth, menu.getPreferredSize().height));
+
+            } else if (!Arrays.equals(menu.getComponents(), menuItems)) {
+                // Scroll is not needed but menu is not up to date
+                menu.removeAll();
+                for (Component item : menuItems) {
+                    menu.add(item);
+                }
+            }
+
+            menu.revalidate();
+            menu.repaint();
         }
     }
@@ -506,15 +415,5 @@
         private void setMenuItems() {
             menuItems = menu.getComponents();
-            int numOfNonSepItems = getNumberOfNonSeparatorItems(menuItems);
-            if (keepVisibleIndex >= topFixedCount
-                    && keepVisibleIndex <= numOfNonSepItems
-                    && (keepVisibleIndex > firstIndex + scrollCount
-                    || keepVisibleIndex < firstIndex)) {
-                firstIndex = Math.min(firstIndex, keepVisibleIndex);
-                firstIndex = Math.max(firstIndex, keepVisibleIndex - scrollCount + 1);
-            }
-            if (numOfNonSepItems > topFixedCount + scrollCount) {
-                refreshMenu();
-            }
+            refreshMenu();
         }
 
@@ -606,20 +505,8 @@
         @Override
         public void mouseWheelMoved(MouseWheelEvent mwe) {
-            if (getNumberOfNonSeparatorItems(menu.getComponents()) > scrollCount) {
-                firstIndex += mwe.getWheelRotation();
-                refreshMenu();
-            }
-            mwe.consume(); // (Comment 16, Huw)
-        }
-    }
-
-    private int getNumberOfNonSeparatorItems(Component[] items) {
-        int result = 0;
-        for (Component c : items) {
-            if (!(c instanceof JSeparator)) {
-                result++;
-            }
-        }
-        return result;
+            firstIndex += mwe.getWheelRotation();
+            refreshMenu();
+            mwe.consume();
+        }
     }
 }
Index: trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java	(revision 7459)
+++ trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java	(revision 7463)
@@ -216,9 +216,8 @@
         }
         if (menuItemHeight > 0) {
-            int scrollcount = MenuScroller.computeScrollCount(subMenu, menuItemHeight);
             if (subMenu instanceof JMenu) {
-                MenuScroller.setScrollerFor((JMenu) subMenu, scrollcount);
+                MenuScroller.setScrollerFor((JMenu) subMenu);
             } else if (subMenu instanceof JPopupMenu) {
-                MenuScroller.setScrollerFor((JPopupMenu)subMenu, scrollcount);
+                MenuScroller.setScrollerFor((JPopupMenu)subMenu);
             }
         }
Index: trunk/src/org/openstreetmap/josm/tools/WindowGeometry.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/WindowGeometry.java	(revision 7459)
+++ trunk/src/org/openstreetmap/josm/tools/WindowGeometry.java	(revision 7463)
@@ -6,6 +6,8 @@
 import java.awt.Component;
 import java.awt.Dimension;
+import java.awt.GraphicsConfiguration;
 import java.awt.GraphicsDevice;
 import java.awt.GraphicsEnvironment;
+import java.awt.Insets;
 import java.awt.Point;
 import java.awt.Rectangle;
@@ -14,4 +16,6 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+
+import javax.swing.JComponent;
 
 import org.openstreetmap.josm.Main;
@@ -367,4 +371,29 @@
         }
         return virtualBounds;
+    }
+
+    /**
+     * Computes the maximum dimension for a component to fit in screen displaying {@code component}.
+     * @param component The component to get current screen info from. Must not be {@code null}
+     * @return the maximum dimension for a component to fit in current screen
+     * @throws IllegalArgumentException if {@code component} is null
+     * @since 7463
+     */
+    public static Dimension getMaxDimensionOnScreen(JComponent component) {
+        CheckParameterUtil.ensureParameterNotNull(component, "component");
+        // Compute max dimension of current screen
+        Dimension result = new Dimension();
+        GraphicsConfiguration gc = component.getGraphicsConfiguration();
+        if (gc == null && Main.parent != null) {
+            gc = Main.parent.getGraphicsConfiguration();
+        }
+        if (gc != null) {
+            // Max displayable dimension (max screen dimension - insets)
+            Rectangle bounds = gc.getBounds();
+            Insets insets = component.getToolkit().getScreenInsets(gc);
+            result.width  = bounds.width  - insets.left - insets.right;
+            result.height = bounds.height - insets.top - insets.bottom;
+        }
+        return result;
     }
 
