<Swing Dev> Force JPopup to be always heavyweight

Mike Swingler swingler at apple.com
Fri Mar 30 18:55:56 UTC 2012


On Mar 30, 2012, at 8:14 AM, Mario Torre wrote:

> Hi all,
> 
> Recently I came across this bug on our bug database:
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=658654
> 
> This is actually a long standing issue that bothered me too for quite
> some time, since the net result is that Java applications look weird
> in some situation (specifically with the native LAF, but also with the
> default ones).
> 
> I think a quick and easy solution that would preserve backward
> compatibility would be to add a system property that allows forcing
> heavy weight rather then medium weight behaviour for popup windows.
> 
> Most of the code is already in place, so probably the changes could
> either go in JPopupMenu.getPopup with the additional advantage of
> being quite circumscribed, for example:
> 
>        PopupFactory popupFactory = PopupFactory.getSharedInstance();
> 
>        if (isLightWeightPopupEnabled()) {
>            popupFactory.setPopupType(PopupFactory.LIGHT_WEIGHT_POPUP);
>        }
>        else if (forceAlwaysHWMenues()) {
>            popupFactory.setPopupType(PopupFactory.HEAVY_WEIGHT_POPUP);
>        }
>        else {
>            popupFactory.setPopupType(PopupFactory.MEDIUM_WEIGHT_POPUP);
>        }
> 
> or in a more general place forcing this to all the popup components to
> be HW. This change could be for example in JPopupFactory.getPopupType,
> right before the beginning of the method, for example:
> 
>        if (owner == null || invokerInHeavyWeightPopup(owner) ||
>            getProperty(PopupFactory_FORCE_HEAVYWEIGHT_POPUP) {
>            popupType = HEAVY_WEIGHT_POPUP;
>        } else if (popupType == LIGHT_WEIGHT_POPUP &&
>                 !(contents instanceof JToolTip) &&
>                 !(contents instanceof JPopupMenu)) {
>            popupType = MEDIUM_WEIGHT_POPUP;
>        }
> 
> I personally don't see much risk for either, but the latter has
> definitely more impact, so having things local to JPopupMenu seems
> better (disclaimer, I didn't try those changes, so maybe more tweaking
> is needed).
> 
> What do you think?
> 
> I would propose those changes for JKD8 of course.
> 
> Cheers,
> Mario
> 
> P.S. I'm not sure if I should include the AWT team in the loop too.

This is also something that should be done with the Aqua Look and Feel on the Mac. It is never appropriate to use a lightweight popup when Aqua is installed, because there is no way that Java can create the appropriate shadow around the popup, correctly layered with other windows (for example, Command-clicking on a partially obscured JComboBox window that is in the background).

I think the Look and Feel should be able to mandate that heavyweights should be used at all times, without slamming a system property, since that is always a valid fallback case that user code has to deal with.

Regards,
Mike Swingler
Apple Inc.




More information about the swing-dev mailing list