I have a component where I want to display custom jtooltip. It's easy, just change the getTooltip method. Similarly for location and text.
However, I also want to change the timers. A tooltip should always be displayed if the mouse is over the cellular agent of the component. If he leaves all this, he must be invisible. I know that I can use TooltipManager to manage time around the world. But the best solution is probably just a short circuit and displaying the prompt itself with the mouse. However, when I tried to do this (unregister the component in the TooltipManager and set the visibility of the tooltip with the text and in the correct position in the mouse listener), the tooltip never showed at all. What am I doing wrong?
Edit: Now the question has changed! In 2 questions.
My solution at the moment is this, but it will lose the shadow that jtooltip always displays sometimes frustratingly, and it is hidden if the mouse enters a popup window. How to filter mouseexit events over a popup if the popup is not even a component? I could do hacking based on lastPosition, but that seems silly since I don't know its width.
private Popup lastPopup;
private final JToolTip tooltip = ...;
private Point lastPoint;
@Override public void mouseMoved(MouseEvent e) {
Point p = privateToolTipLocation(e);
if (p == null || p.equals(lastPoint)) {
return;
}
lastPoint = p;
tooltip.setTipText(privateToolTipText(e));
p = new Point(p);
SwingUtilities.convertPointToScreen(p, this);
Popup newPopup = PopupFactory.getSharedInstance().getPopup(this, tooltip, p.x, p.y);
if (lastPopup != null) {
lastPopup.hide();
}
lastPopup = newPopup;
newPopup.show();
}
@Override public void mouseExited(MouseEvent e) {
if (lastPopup != null && someUnknownCondiction) {
lastPopup.hide();
lastPopup = null;
}
}
source
share