-
Notifications
You must be signed in to change notification settings - Fork 106
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
Hovering: setLocation does not work (wrong position) #27
Comments
Thanks - I will look at it asap .. |
just wanted to let you know. I've also tried to add other Swing components, e.g., JPanel: the bug (?) is always the same, position is always top center. |
The original example from java.net are heavily outdated - still, the code should work. I was not able to reproduce the problem. This is why I've created a new sample that uses JXMapKit and a roll-over tooltip. Does this solve your problem? |
Okay I think I've found the issue. I was iterating over a bunch of items and checked whether there was one item within a certain distance to the mouse pointer. If so, I set its position and breaked the for-loop. If not, I was calling tooltip.setVisible(false) and continued to check for the next item. Calling all these setVisible(false) before the first (and final) setVisible(true) made the functionality somehow broke. Here the broken code: for (DataItem di : twitterDataManager.getDataItems()) {
GeoLocation gl = twitterDataManager.getGeoLocation(di);
...
// check if near the mouse
if (screenPos.distance(e.getPoint()) < 20) {
mytip.setLocation(screenPos);
isVisible = true;
break;
} else {
mytip.setVisible(false);
}
} And this is the version that works: boolean isVisible = false;
// iter over all tweet locations
for (DataItem di : twitterDataManager.getDataItems()) {
GeoLocation gl = twitterDataManager.getGeoLocation(di);
...
// check if near the mouse
if (screenPos.distance(e.getPoint()) < 20) {
mytip.setLocation(screenPos);
isVisible = true;
break;
} else {
}
}
mytip.setVisible(isVisible); So this still might be a bug, which is however caused by calling repeatedly setVisible(false) before actually calling setVisible(true) and setting the proper position. |
However, I am experiencing flickering now. It seems like the label initially pops up at the top center position for a short time, before actually being displayed at the correct position. if (closestDataItem != null) {
tooltip.setDataItem(closestDataItem);
tooltip.setLocation(closestScreenPos);
tooltip.setVisible(true);
} else {
tooltip.setVisible(false);
} Here a video showing the flickering effect. |
I can confirm this, but I cannot explain the jumping behaviour of the tooltip. Please let me know if you find the reason for that. |
Alright, if I find something, I'll let you know here :-) |
Hi,
![screenshot from 2014-05-26 14 18 25](https://cloud.githubusercontent.com/assets/6160304/3082245/e687859a-e4cf-11e3-8eed-4b0830103b10.png)
I'm performing this tutorial: https://today.java.net/pub/a/today/2007/11/13/mapping-mashups-with-jxmapviewer.html#waypoint-rollovers
The rollover JLabel is not added at the correct position, it is always displayed at the top, horizontal center.
My code, however, should place it at the mouse pointer position:
The text was updated successfully, but these errors were encountered: