O'Reilly logo

Ivor Horton's Beginning Java™ 2, JDK™ 5th Edition by Ivor Horton

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

19.2. Coordinate Systems in Components

In Chapter 17, you saw how your computer screen has a coordinate system that is used to define the position and size of a window. You also saw how you can add components to a container with their position established by a layout manager. The coordinate system used by a container to position components within it is analogous to the screen coordinate system. The origin is at the top-left corner of the container, with the positive x-axis running horizontally from left to right, and the positive y-axis running from top to bottom. The positions of buttons in a JWindow or a JFrame object are specified as a pair of (x, y) pixel coordinates, relative to the origin at the top-left corner of the container object on the screen. In Figure 19-2 you can see the coordinate system for the Sketcher application window.

Figure 19.2. Figure 19-2

Of course, the layered pane for the window object will have its own coordinate system, with the origin in the top-left corner of the pane, and this is used to position the menu and the content pane. The content pane will have its own coordinate system, too, which will be used to position the components that it contains.

It's not just containers and windows that have their own coordinate system: Each JButton object also has its own system, as do JToolBar objects. In fact, every component has its own coordinate system, ...

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