• Post Reply Bookmark Topic Watch Topic
  • New Topic

Image.getBounds does not return the actual image position on the screen

 
Sanjeev Mehta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have drawn an image on a Composite using the following code



Now, I am trying to check the image position on the screen using the image.getBounds function. However, the function returns a bounds value of (0, 0) instead of (120, 150).
I am not sure why that happens. How do I get the actual bounds of the image?
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getBounds() returns the bounds within the parent container. You would need to translate that to the screen position. Fortunately that's not that hard. You can use getLocationOnScreen() to get the absolute location (X,Y) based on the screen itself, not the parent. Just modify the X and Y values of the Rectangle to those of the screen location.

Edit: that's of course the AWT / Swing way to go. For SWT that won't work, but there's an answer here.
 
Sanjeev Mehta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
toDisplay can only be used on classes derived from the Control class in SWT. Is there a way to get the screen coordinates for an image?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!