GlassPane - JComboBox
Hi,
I have a glass pane, which redispatches all mouse, mouse motion, and mouse wheel events. I have a JComboBox under the glass pane. When I mouse over the combo and click on it, the popup menu appears. But when I move my mouse on the popup menu, the item that my mouse moves over does not become selected/highlighted as normal. I can select the item, but it doesnt look like I am selecting it.
Any ideas?
I already set, JComboBox.setLightWeightPopupEnabled(false);
[490 byte] By [
codecraiga] at [2007-10-2 11:13:27]

I have just finished working on a similar glasspane problem.
First of all, I'm assuming you're redispatching the events to the component you find using
SwingUtilities.getDeepestComponentAt(...).
When you make the above call, make sure you're looking for the components on the Layered Pane and not the Content Pane. Popups render on the layered pane, and if you look for the components on the content pane, you won't find it.
However, this will only work if you're using a lightweight component. Your call to
setLightWeighPopupEnabled(false)
will cause it to appear as a seperate JDialog and render above the glasspane you're using. I can't help you there.
My 2 cents about searching for deep components...
I usually start searches for components at the window level.
You suggest doing it at the layered pane instead of the content pane (since the content pane is below the layered pane, searching the content pane misses components in the layered pane). Good idea, but why stop there?
Take it a step further... the JRootPane is next up, which is just a JComponent containing the glasspane, layered pane, content pane, etc, and the Window is above that. Just start searching at the window, which you know is at the top of the component hierarchy.
Technically it's possible to put components directly in the Window, so you can't really say you've found the deepest component unless you search starting at the window.
Also, SwingUtilities only returns the deepest VISIBLE component (i.e., the component must be realized in the component hierarchy) If you are searching for something that renders itself and is not in the component hierarchy, then you will not find it.
> However, this will only work if you're using a
> lightweight component. Your call to
> setLightWeighPopupEnabled(false)
> will cause it to appear as a seperate JDialog and
> render above the glasspane you're using. I can't help
> you there.
Here is what you can do in this case:
Get the window that contains the JComboBox and search it's owned windows to find the combo box popup:
Window w = SwingUtilities.getWindowAncestor(JComboBox);
Window[] windows = window.getOwnedWindows();
for(int i = 0; i < windows.length; i++) {
Component c = SwingUtilities.getDeepestComponentAt(window[i], x, y);
// check if c is the combo box popup, etc.
}
Good point about searching from the top of the window, although I would not normally expect to find components there.
As far as your example for heavyweight popups, I suppose you would also need to add a listener on the popup window in order to receive mouse events on the underlying glasspane.