Bug #571


fix height of toolbar on windows

Added by Matt Jones almost 22 years ago. Updated almost 22 years ago.

morpho - general
Target version:
Start date:
Due date:
% Done:


Estimated time:


The toolbar in MorphoFrame is sized by subtracting the height of the menu bar
from the hieight of the Progress Indicator. Unfortunately, JMenuBar.getHeight()
and similar methods always return zero. So I have not yet found a way to
accurately determine the actual menu bar height.

On linux, the menu bar is 24 pixels tall, so I have hardcoded a value for that
OS, although it might not apply to all Look and Feels. It results in a tollbar
that is 1 or 2 pixels too short on Windows, so it looks funny. This needs to be

Ideally I would be able to find a reliable way to determine the menu height,
then I could accurately calculate the proper toolbar height.

If that's not possible, I could write a routine that provides fixed defaults for
the various operating system/l&f combinations, and a default. This is a kludge
but would probably work reasonably well.

One other possibility is to try to fix the menu bar at soe height that is
greater than its native height by adding a rigid component (its a box layout) of
a fixed size (e.g., 25 pixels). Again, a kludge, and this one might not work.

Ideas, or suggestions on how to get JMenuBar.getSize() to work?

Actions #1

Updated by Matt Jones almost 22 years ago

Looks like brooke fixed it by using getPreferredSize() instead of getSize().
FIXED. (Wow that was easy :)

Actions #2

Updated by Matthew Brooke almost 22 years ago

Good grief - I finally manage to fix a bug, and Jones gets here and posts a
comment before me... :-)


Fixed menubar height detection problem by using getPreferredSize(), and fixed
toolbar height hack by using setPreferredSize().

This works because the preferredSize attribute has the correct value even before
the component is displayed, whereas the value returned by calling getSize() is
zero until the component appears on the screen.

In addition to changing code in
src/edu/ucsb/nceas/morpho/framework/, I made 2 methods static in
b/nceas/morpho/framework/, and made one of them -
createToolBar() - protected instead of private, so it can be called directly
from MorphoFrame to create a "test" menubar instance in order to get the menu
bar dimensions.

There may be a less wasteful way of doing this, but this was the best I could do
on a Friday afternoon ;-)

Actions #3

Updated by Redmine Admin over 11 years ago

Original Bugzilla ID was 571


Also available in: Atom PDF