JDK-4248733 : Poor heavy/medium-weight choices done by ToolTipManager and JPopupMenu
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 1999-06-23
  • Updated: 2000-09-15
  • Resolved: 2000-09-15
Related Reports
Duplicate :  
Description

Name: vi73552			Date: 06/22/99


This is the source code from javax.swing.ToolTipManager.

At the very bottom of the text you will see the exact bug.
A tooltip will not be displayed properly in a JLayeredPane
because a "middle-weight" instead of a "Heavyweight" component
is being used to display the tooltip.  This problem is also
prevalent in JPopupMenu as well -- your "intelligent" choice
of middleweight vs heavyweight is not always a good one.  You
should provide an API from which programmers can say either
LightWeight or MiddleWeight or HeavyWeight or Choose.

Because you're not exactly aware of what the programmer is
doing with the component, your choice is not always the best
one.  There _MUST_ be a way of overridding LightWeight vs
Mediumweight vs Heavyweight.  That would make a lot of 
programmer's jobs MUCH EASIER.  

Here is the "faulty" tooltip choice in 
javax.swing.ToolTipManager.java:



void showTipWindow() {
        if(insideComponent == null || !insideComponent.isShowing())
            return;
        if (enabled) {
            Dimension size;
            Point screenLocation = insideComponent.getLocationOnScreen();
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            Point location = new Point();

            // Just to be paranoid
            hideTipWindow();

            tip = insideComponent.createToolTip();
            tip.setTipText(toolTipText);
            size = tip.getPreferredSize();

	    // fix bug 4135787: Tooltips don't work when used in awt.Frame or awt.Applet, etc
	    // this is a quick and dirty check 
	    if (insideComponent.getRootPane() == null){
	      tipWindow = new WindowPopup((frameForComponent(insideComponent)),tip,size);
	      heavyWeightPopupEnabled = true;
	    }
	    else if (lightWeightPopupEnabled){
	      heavyWeightPopupEnabled = false;
	      tipWindow = new JPanelPopup(tip,size);
	    }
	    else {
	      heavyWeightPopupEnabled = false;
	      tipWindow = new PanelPopup(tip,size);
	    }



The other "minor" bug here is that heavyWeightPopupEnabled
is beign set to "false" in both cases.  Although probably
an issue, it is not related to my problem per se.

The _only_ solution to this is to allow the programmer to
choose Heavy/Medium/Light-weight.  Swing is cool, but there
are really times when you absolutely _must_ include the
HeavyWeight components because you simply have no other
alternative.

PLEASE fix this, as the fix is very simple and should not
impact a lot of code.  It is simply a matter of adding an
API to allow programmers to "override" the heavy/medium-weight
choice.  It is a couple of hours work at most, and should not
impact the rest of the system.
(Review ID: 84292) 
======================================================================

Comments
WORK AROUND Name: vi73552 Date: 06/22/99 There is no real "good" workaround to this problem because everything significant in ToolTipManager and everything in JPopupMenu is private. Because they are private -- including ToolTipManager.sharedInstance -- you cannot extend the class and make it behave correctly. The only feasible workaround is to either edit the ToolTipManager and JPopupMenu source code. ======================================================================
11-06-2004

EVALUATION Name: apC97674 Date: 11/19/99 The source code was slightly changed, but some remarks from description should be considered. ###@###.### ====================================================================== As part of 4303635 in 1.4 we will be exposing Popup and PopupFactory. It will be possible for you to replace the PopupFactory with one that always returns heavy weights, or something even trickier if you desire. We would prefer not to expose the three types as we are hoping in the near future to be able to only have one that works equally well on all platforms in all cases. scott.violet@eng 2000-09-15
15-09-2000