views:

54

answers:

2

How do I get JLabel location instead of top left x/y location of the object in Java?

+1  A: 

You can use JLabel.getBounds(). With that Rectangle you can find whatever notion of location it is you're looking for. You can do similar things with JLabel.getLocation() followed by JLabel.getWidth() and JLabel.getHeight().

JLabel.getVisibleRect() is also handy in some cases. If you are actually looking to find the location relative to a coordinate system other than the JLabel's parent, you can use SwingUtilities to do the conversion.

Yuvi Masory
A: 

You can get the X&Y by the getLocation(), then the getSize() tells you how big it is.

You can do the math to figure out the bottom right and middle. (x + width = left edge, y + height = bottom edge.)

Kylar