DialogBoxes and MenuBars . . . zIndexing a bad thing?

46 views
Skip to first unread message

King_V

unread,
Nov 11, 2011, 3:52:56 PM11/11/11
to Google Web Toolkit
All,

I'm working on my ever-evolving bit of code, and have run across
something of an issue. My apologies for the lengthy prelude before I
get to the actual question.

Firstly, I have a "full-browser-screen" display - a DockLayoutPanel.

Within it are a:
MenuBar - NORTH
FlowPanel - SOUTH

Now, there's a big empty section in the middle, which is fine because
that's what I want.

The MenuBar looks like a typical application - File, with sub-items
Open, Close, etc. Edit, with sub-items Copy, Paste, etc.

I have also created a, for lack of a better term, WindowPrototype
class that extends DialogBox. It has a close button, minimize, and
maximize. I have not yet done draggable resizing with the corners and
edges.

So, my test code basically, when an item in the menu is chosen, it
launches one of my WindowPrototype objects (which is mostly empty,
just some text to show which item in the menu launched it).

Now, of course, by default, DialogBox does not allow popping up of non-
modal instances of itself over each other. The LAST one shown is
ALWAYS on top - clicking on a partially hidden one does NOT bring it
to the top.


To get around this, I used a trick I came across on a web-search which
puts a static int in the class that extends DialogBox (in my case, the
WindowPrototype class), and increments it every time a new
WindowPrototype is opened, or one is clicked to be brought to the top.

This actually works fine as far as my WindowPrototype objects are
concerned.

However, when I do this, then there's a problem with the MenuBar
items. If I click on a menu item, say File, then the subitems (Open,
Close, etc) are shown UNDER any WindowPrototype object that happens to
be in the area - the WindowPrototypes will obscure the menu items.

Now that I've written half a novel, here's my question: How do I add
the ability for my WindowPrototype objects to be clicked on to bring
to the top, but ALSO make sure that the MenuBar items are ALWAYS on
top of any/all WindowPrototypes that may be on the screen?

Thanks in advance.

King_V

unread,
Nov 11, 2011, 4:17:31 PM11/11/11
to Google Web Toolkit
Well, this is embarrassing, but maybe the answer will help someone
else who's run into the same problem.

Override the onBrowserEvent() method in my own subclass of DialogBox
as follows:

@Override
public void onBrowserEvent(Event event) {
switch(event.getTypeInt()) {
case Event.ONMOUSEDOWN:
hide();
show();
}
super.onBrowserEvent(event);
}

And that does it, with no ill effects in terms of obscuring the
MenuBar objects. Sheesh, I must now hold the record for shortest time
between someone posting and answering their own question!

King_V

unread,
Nov 18, 2011, 2:42:14 PM11/18/11
to Google Web Toolkit
For anyone who has actually followed this - my solution (the hide()
followed by show()) is not actually a particularly viable solution.
It works, more or less, as long as there are no items inside the
Window (the class that extends DialogBox), such as Buttons, TextBoxes,
etc.

In Firefox 5, a Button will still work, but a TextBox will never be
able to get focus.

In IE8, a Button will require a double-click to work, but a TextBox
can still be used correctly.

I don't know what other side effects will happen with other Widgets.

Back to the drawing board....
Reply all
Reply to author
Forward
0 new messages