Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird tooltip positioning #164

Closed
mlaggner opened this issue Aug 24, 2020 · 4 comments
Closed

Weird tooltip positioning #164

mlaggner opened this issue Aug 24, 2020 · 4 comments
Milestone

Comments

@mlaggner
Copy link

I've created a window with an error indicator in the lower right corner which shows a tooltip (flat JButton) when hovered with the mouse like
Screenshot_20200824_180436

but when I maximize the window (or move it to the lower right corner of the screeen), the tooltip hoveres the JButton which become unclickable
Screenshot_20200824_180506

doing the same in IntelliJ (which is a swing UI too), this behaves as intended:
Screenshot_20200824_180929
Screenshot_20200824_181020

is there anything we can do by the LaF?

@DevCharly
Copy link
Collaborator

Yep, that positioning is weird...

Class javax.swing.ToolTipManager does the tooltip positioning.
It simply checks whether the tooltip is (partly) outside of the screen and then moves x,y so that it is inside.

See https://github.com/openjdk/jdk/blob/bcff4990ad9db20d11c59841a409717118645a65/src/java.desktop/share/classes/javax/swing/ToolTipManager.java#L321-L334

IntelliJ IDEA does not use javax.swing.ToolTipManager.
They use IdeTooltipManager and HelpTooltipManager and HelpTooltip with RelativePoint,
which seems to do the out-of-screen position fix if necessary.

So there is no easy fix for this.

Will try to solve it in FlatPopupFactory.getPopup(), which is used to display tooltips (and other popups).
But need the x,y location of the mouse pointer (from the last MouseEvent), which is not passed to this method...

@DevCharly
Copy link
Collaborator

@mlaggner in case of your notification button, which is always in lower-right corner of window, it would be better to show the notification tooltip always above the button (as in IntelliJ IDEA). You can do this by overriding Point getToolTipLocation(MouseEvent event) of the button and compute the tip location yourself. Create a temporary tooltip to compute the preferred size of the tooltip. E.g.

Point getToolTipLocation(MouseEvent event) {
    JToolTip tip = new JToolTip();
    tip.setTipText( getToolTipText() );
    Dimension tipSize = tip.getPreferredSize();

    // TODO compute tip location based on tipSize and upper-right corner of button
}

@mlaggner
Copy link
Author

thanks for your great help (once more).
I managed to create a custom tooltip location for all components in the status bar with getToolTipLocation and some code of HelpTooltip.java.

Nevertheless, it would be great if the LaF could manage such corner cases!

@DevCharly
Copy link
Collaborator

fixed in 0.42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants