I am trying to get the coordinates of a component, for example a label. I tried getBounds, and getLocation, however they do not give accurate coordinates if the label is on 2 or more panels. Besides getLocationOnScreen, is there a way to be able to get accurate components’ coordinates, even though they are on more than 1 panel?
Share
If you want it relative to a JFrame, then you’ll have to do something like this:
Or you can just use the built-in solution
SwingUtilities.convertPoint(comp, 0, 0, root).