-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1.2
-
sparc
-
solaris_2.5.1
(Me again, sorry!) This is with the latest JDK1.1-AWT workspace.
If you have put a lightweight container into a parent container, then its
heavyweight contents may show up at the parent's 0,0 instead of inside the
lightweight container.
See the following example. The Jellybean shows up at the top left
rather than inside the square box drawn by its containing Wrapper.
This works correctly if you make Wrapper heavyweight by subclassing
Panel instead of Container.
If you jiggle the code around so you do the setBounds after adding
the Wrapper to the Frame, then things also work better.
Unfortunately the scenario where I run into this is when I'm reading
in some serialized objects and putting them into a container. All
the bounds, etc, have been read in as part of the serialized object,
so I simply have a complete pre-formed Wrapper that I need to
insert into a higher level container. So I can't simply rearrange
the setup code.
KGH 5/5/97
import java.awt.*;
class Wrapper extends Container {
public void paint(Graphics g) {
// draw a bounding box.
int width = getSize().width;
int height = getSize().height;
g.drawLine(0, 0, width-1, 0);
g.drawLine(0, 0, 0, height-1);
g.drawLine(width-1, 0, width-1, height-1);
g.drawLine(0, height-1, width-1, height-1);
super.paint(g);
}
}
class JellyBean extends Canvas {
public void paint(Graphics g) {
g.setColor(Color.red);
g.fillArc(5, 5, 30, 30, 0, 360);
g.fillArc(25, 5, 30, 30, 0, 360);
g.fillRect(20, 5, 20, 30);
}
public Dimension getPreferredSize() {
return new Dimension(50,80);
}
}
public class Test {
public static void main(String argv[]) {
Frame fram = new Frame("Test");
fram.setLayout(null);
Wrapper w = new Wrapper();
w.setLayout(null);
JellyBean jb = new JellyBean();
fram.setSize(300,300);
fram.show();
jb.setBounds(5,5,80,80);
w.add(jb);
w.setBounds(160,160,100,100);
fram.add(w);
}
}
- duplicates
-
JDK-4047668 Lightweight container does not layout heavyweight component(s) correctly
-
- Closed
-