| getLocationInRoot |
(Object comp) |
yoix.swing |
| |
Returns a
Point
that represents the location of
comp,
which should be an AWT or Swing component, relative to its
root
in a coordinate system that has its origin in the upper left corner of
root
positive x to the right, positive y down, and a resolution of 72 dots per inch.
getLocationInRoot
returns
NULL
when
comp
has a
NULL
root
or when
comp
is a top-level application window, like a
JFrame
or
JDialog.
| |
| Example: |
The program,
import yoix.*.*;
JFrame f = {
int opaque = FALSE;
BoxLayout layoutmanager;
Array layout = {
72,
new JPanel {
GridBagLayout layoutmanager;
Array layout = {
new JLabel {
String text = "This is a Label";
Color background = Color.yellow;
int alignment = CENTER;
},
new GridBagConstraints {
int gridwidth = REMAINDER;
Insets insets = {
double top = 72/4;
double bottom = 72;
};
},
new JPanel {
GridLayout layoutmanager = {
double hgap = 72/2;
};
Array layout = {
new JButton {
String text = "Outline";
actionPerformed(e) {
root.DrawOutlines();
}
},
new JButton {
String text = "Clear";
actionPerformed(e) {
root.repaint();
}
},
new JButton {
String text = "Dismiss";
actionPerformed(e) {
exit(0);
}
},
};
},
new GridBagConstraints {
int gridwidth = REMAINDER;
Insets insets = {
double top = 2*72;
double bottom = 72/4;
};
},
};
},
72,
};
DrawOutlines() {
Rectangle rect;
Dimension size;
Object comp;
Point location;
int n;
graphics {
setrgbcolor(1, 0, 0);
for (n = 0; n < components@sizeof; n++) {
comp = components[n];
if (!(comp instanceof JPanel)) {
size = comp.size;
location = getLocationInRoot(comp);
rect.x = location.x - 72/8;
rect.y = location.y - 72/8;
rect.width = size.width + 72/4;
rect.height = size.height + 72/4;
rectstroke(rect);
}
}
}
}
};
f.visible = TRUE;
creates a frame containing buttons and a label that uses
getLocationInRoot
to help draw the outline a red rectangle around each of the components.
You should also notice that we set
opaque
to
FALSE
in the
JFrame
so we could draw in the frame and still see the boxes.
Try setting
opaque
to
TRUE
and then see what happens when you make the
JPanel
transparent.
| | |
| Return: |
Point
| | |
| See Also: |
getLocationOnScreen
|
|
Yoix is a registered trademark of AT&T Inc.
|