Changeset 8075 in josm for trunk/src


Ignore:
Timestamp:
2015-02-16T21:47:42+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #10882 - dynamic resize of search box for low resolutions

File:
1 edited

Legend:

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

    r8072 r8075  
    804804    }
    805805
     806    private int getMaximumAvailableWidth() {
     807        int maxWidth = getSize().width;
     808        for (int i = 0; i < getMenuCount(); i++) {
     809            JMenu menu = getMenu(i);
     810            if (menu != null) {
     811                maxWidth -= menu.getPreferredSize().width;
     812            }
     813        }
     814        return maxWidth;
     815    }
     816
    806817    /**
    807818     * Create search field.
    808819     */
    809820    private JComponent createSearchField() {
    810         DisableShortcutsOnFocusGainedTextField searchField = new DisableShortcutsOnFocusGainedTextField();
     821        DisableShortcutsOnFocusGainedTextField searchField = new DisableShortcutsOnFocusGainedTextField() {
     822            @Override
     823            public Dimension getPreferredSize() {
     824                // JMenuBar uses a BoxLayout and it doesn't seem possible to specify a size factor,
     825                // so compute the preferred size dynamically
     826                return new Dimension(Math.min(200, Math.max(25, getMaximumAvailableWidth())),
     827                        helpMenu.getPreferredSize().height);
     828            }
     829        };
    811830        searchField.setEditable(true);
    812         Dimension d = new Dimension(200, helpMenu.getPreferredSize().height);
    813         searchField.setPreferredSize(d);
    814         searchField.setMaximumSize(d);
     831        searchField.setMaximumSize(new Dimension(200, helpMenu.getPreferredSize().height));
    815832        searchField.setHint(tr("Search menu items"));
    816833        searchField.setToolTipText(tr("Search menu items"));
Note: See TracChangeset for help on using the changeset viewer.