melody
unread,Jul 2, 2009, 3:17:34 PM7/2/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Google Web Toolkit
I have had problems with MenuBar submenus not repositioning or
resizing when there is more menu items than can fit in the height
available.
So I decided to copy MenuBar.java and made the following changes
add the following member variables and static members
<code>
private int oldOffsetHeight = -1;
private static final int MIN_MENUHEIGHT = 200;
<code>
in private void onHide() method, add the following code segment
<code>
//reset the offset height to what was originally
if (oldOffsetHeight != -1) {
setHeight(Utils.toHTMLPixels(oldOffsetHeight));
}
oldOffsetHeight = -1;
</code>
In method void doItemAction(final MenuItem item, boolean fireCommand),
change the setPosition method of PopupPanel.PositionCallback as
shown
<code>
public void setPosition(int offsetWidth, int offsetHeight) {
// depending on the bidi direction position a menu on the left
or right
// of its base item
if (LocaleInfo.getCurrentLocale().isRTL()) {
if (vertical) {
popup.setPopupPosition(MenuBar.this.getAbsoluteLeft() -
offsetWidth + 1,
item.getAbsoluteTop());
} else {
popup.setPopupPosition(item.getAbsoluteLeft() +
item.getOffsetWidth() - offsetWidth,
MenuBar.this.getAbsoluteTop() +
MenuBar.this.getOffsetHeight() - 1);
}
} else {
if (vertical) {
int left = shownChildMenu.parentMenu.getAbsoluteLeft() +
shownChildMenu.parentMenu.getOffsetWidth();
int top = item.getAbsoluteTop();
if (top + offsetHeight > Window.getClientHeight())
{
int li_offsetHeight = Window.getClientHeight() - top;
if (li_offsetHeight < MIN_MENUHEIGHT) {
li_offsetHeight = MIN_MENUHEIGHT;
top = Window.getClientHeight() - li_offsetHeight;
}
oldOffsetHeight =
shownChildMenu.parentMenu.getOffsetHeight();
shownChildMenu.setHeight(Utils.toHTMLPixels
(li_offsetHeight));
}
popup.setPopupPosition(left, top);
} else {
popup.setPopupPosition(item.getAbsoluteLeft(),
MenuBar.this.getAbsoluteTop() + MenuBar.this.getOffsetHeight() - 1);
}
}
}
</code>
If there is GWT committer out there who is willing to take this code
and put into GWT please feel free. Its working wonders for me and I
believe that is how menubar should work. Or Better
Thanks,
Melody