O'Reilly logo

Graphic Java™ 1.2, Volume I: AWT, Third Edition by David M. Geary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Component Location, Bounds, and Coordinates

A component's location is relative to the container in which it resides, whereas its bounds represent the actual pixel width and height of the component. If you'd like to find out the actual screen coordinates of a component, use the new method introduced in the 1.1 version of the AWT:

Point java.awt.Component.getLocationOnScreen()

Coordinates used in component methods are relative to the upper left-hand corner of the component in question. If you wish to draw a rectangle in a canvas, for example, and you specify the location of the rectangle as (10,10), the upper left-hand corner of the rectangle will be located 10 pixels below and to the right of the upper left-hand corner of the canvas.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required