-
Bug
-
Resolution: Duplicate
-
P1
-
None
-
1.1.2
-
None
-
sparc
-
solaris_2.5.1
I was trying to upgrade the BeanBox to have better support for
lightweight components.
I converted our key container class "Wrappr" to be a lightweight
container. It works OK when it only contains lightweight beans.
However if you put a heavyweight bean inside the lightweight
Wrapper, it behaves wrongly on moves. When the Wrapper gets
moved its contents get left behind at the old location.
I couldn't find any reasonable workaround, so I've had to backoff
and revert the Wrapper to being heavyweight.
Here's a small example that demonstrates the problem. Initially
the wrapper and its contained JellyBean appear in the top left.
After 5 seconds we move them to the bottom right. But only the
Wrapper moves, the JellyBean gets left behind.
If you make the Jellybean "lightweight", the problem goes away. But
I have to be able to deal with existing heavyweight components. :-(
An OK annswer to this bug is to say that lightweight containers
can't contain heavyweight components. Then I can stop worrying
about it. ;-) But it might be worth enforcing that in the container
code.
KGH 4/27/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();
fram.add(w);
w.setBounds(20,40,100,100);
w.add(jb);
jb.setBounds(5,5,80,80);
try {
Thread.sleep(5000);
} catch (Exception ex) {
}
w.setBounds(160,160,100,100);
w.repaint();
fram.repaint();
jb.repaint();
}
}
- duplicates
-
JDK-4047668 Lightweight container does not layout heavyweight component(s) correctly
- Closed