<Swing Dev> Force JPopup to be always heavyweight

Pavel Porvatov pavel.porvatov at oracle.com
Mon Apr 2 14:21:53 UTC 2012


Hi Mario,

I'd suggest to change the javax.swing.JPopupMenu#getPopup method:

         if (isLightWeightPopupEnabled()) {
             popupFactory.setPopupType(PopupFactory.LIGHT_WEIGHT_POPUP);
         }
         else {
             popupFactory.setPopupType(PopupFactory.HEAVY_WEIGHT_POPUP); 
// Replaced MEDIUM_WEIGHT_POPUP
         }

I don't see any regressions, what do you think about that?

Regards, Pavel

> 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.




More information about the swing-dev mailing list