Java Reference
In-Depth Information
Of course, the layered pane for the window object has 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 has
its own coordinate system, too, which is 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, and an
example is shown in Figure 19-3 .
FIGURE 19-3
The toolbar and the buttons each have their own independent coordinate systems with the origin in the
top-left corner. It's clear that a container needs a coordinate system for specifying the positions of the com-
ponents it contains. You also need a coordinate system to draw on a component — to draw a line, for ex-
ample, you need to be able to specify where it begins and ends in relation to the component. Although the
coordinate system you use for drawing on a component is similar to that used for positioning components
in a container, it's not exactly the same. It's more complicated when you are drawing — but for very good
reasons. Let's see how the coordinate system for drawing works.
DRAWING ON A COMPONENT
Before I get into the specifics of how you draw on a Swing component, I will explain the principle ideas
behind it. When you draw on a component using the Java 2D capabilities, two coordinate systems are in-
volved. When you draw something — a line or a curve, for example — you specify the line or the curve
in a device-independent logical coordinate system called the user coordinate system for the component, or
user space . By default, this coordinate system has the same orientation as the system that I discussed for
 
 
Search WWH ::




Custom Search