JDK-6401412 : Tooltips do not show for unfocused frames
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-03-21
  • Updated: 2011-02-16
  • Resolved: 2006-03-23
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
The Swing's Tooltip Manager cannot show tooltips for widgets that are in unfocused top-level windows. The only exceptions is a JPopupMenu.

JUSTIFICATION :
There are other circumstances (besides popup menu) when you want to show tooltips even if the window is not focused, such as floating toolbars (see example below)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
One possibility is to allow per whole JVM session tooltips for unfocused windows This usually does not cause any harm anyway. Another possibility is to allow it more selectively.
ACTUAL -
the tooltips are not allowed for unfocused top-level windows, except the tooltipee has JPopupMenu in its containment hierarchy, as can be seen from the following snippet of the javax.swing.ToolTipManager.showTipWindow():

    void showTipWindow() {
        if(insideComponent == null || !insideComponent.isShowing())
            return;
	for (Container p = insideComponent.getParent(); p != null; p = p.getParent()) {
            if (p instanceof JPopupMenu) break;
	    if (p instanceof Window) {
		if (!((Window)p).isFocused()) {
		    return;
		}
		break;
	    }
	}
[snip]

---------- BEGIN SOURCE ----------
package bugs;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JFrame;
import javax.swing.JToolBar;

public class ToolbarTooltipBug extends JFrame {

	public ToolbarTooltipBug() {
		JToolBar bar = new JToolBar();
		AbstractAction action = new AbstractAction("button") {
			public void actionPerformed(ActionEvent e) {
			}
		};
		action.putValue(AbstractAction.SHORT_DESCRIPTION, "tooltip");
		bar.add(action);
		getContentPane().add(bar, BorderLayout.PAGE_START);
		pack();
		// now undock the toolbar by dragging it off the frame, and activate the
		// frame, and hover mouse over the button; the tooltip does not pop up
	}

	public static void main(String[] args) {
		new ToolbarTooltipBug().setVisible(true);
	}

}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
perhaps display floating toolbars in a popup menu, (may have other side effects, I didn't try it), or not to use TooltipManager for tooltips, which would be a lot of work and duplicated code. Another workaround is to focus the floating toolbar upon mouse motion detection, which also has side effects.

Comments
EVALUATION Duplicate of 6178004, which is in progress for Mustang.
23-03-2006