Get object location Java2D (not corner)
How do I get JLabel location instead of top left x/y location of the object in Jav开发者_StackOverflow中文版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.
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.)
精彩评论