<Swing Dev> Force JPopup to be always heavyweight

Mario Torre neugens.limasoftware at gmail.com
Fri Mar 30 15:14:58 UTC 2012


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.
-- 
pgp key: http://subkeys.pgp.net/ PGP Key ID: 80F240CF
Fingerprint: BA39 9666 94EC 8B73 27FA  FC7C 4086 63E3 80F2 40CF

IcedRobot: www.icedrobot.org
Proud GNU Classpath developer: http://www.classpath.org/
Read About us at: http://planet.classpath.org
OpenJDK: http://openjdk.java.net/projects/caciocavallo/

Please, support open standards:
http://endsoftpatents.org/



More information about the swing-dev mailing list