开发者

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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜