-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
1.1.5
-
Cause Known
-
x86
-
windows_95
Name: skT88420 Date: 08/23/99
The following class demonstrates the problem.
(just compile and run it - it is small and self contained)
It paints a screen and then calls invalidate and validate
20 times at one second intervals. You will see the components
on the screen move slowly apart.
If you change the ipadx and ipady to zero the problem disappears
//package sun.javaos ;
import java.awt.* ;
public class pw
{
public static void main(String [] args)
{
ThingWatcher d = new ThingWatcher() ;
d.pack() ;
d.show() ;
for (int i = 0 ; i < 20 ; i++)
{
try{Thread.sleep(1000);}catch(Exception e){}
d.invalidate() ;
d.validate() ;
}
}
}
class ThingWatcher extends Frame
{
public ThingWatcher()
{
super("ThingWatcher");
setLayout (new FlowLayout()) ;
Font f = new Font("Dialog", Font.PLAIN, 12);
setFont(f) ;
add(new WotsitPanel()) ;
/*
add(new Blob(Color.red, 10)) ;
add(new Blob(Color.green, 10)) ;
*/
}
class WotsitPanel extends Panel
{
Blob leftBlob, midBlob, rightBlob ;
Blob b ;
Label lbl ;
TextField t ;
GridBagLayout g = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints() ;
WotsitPanel()
{
setLayout( g ) ;
//c.fill = c.BOTH ;
c.gridy = 0 ;
c.ipadx = 2 ; // Set these to 0 and see what happens!
c.ipady = 1 ;
leftBlob = new Blob(Color.red, 10) ;
c.gridx = 0 ;
g.setConstraints(leftBlob,c) ;
add(leftBlob) ;
midBlob = new Blob(Color.green, 10) ;
c.gridx = 1 ;
g.setConstraints(midBlob,c) ;
add(midBlob) ;
rightBlob = new Blob(Color.green, 10) ;
c.gridx = 2 ;
g.setConstraints(rightBlob,c) ;
add(rightBlob) ;
//c.ipadx = c.ipady = 0 ;
t = new TextField("Title") ;
t.setEditable(false) ;
c.gridx = 3 ;
c.anchor = c.WEST ;
g.setConstraints(t,c) ;
add(t) ;
//c.anchor = c.CENTER ;
c.gridwidth = 2 ;
DooDaaPanel fp = new DooDaaPanel("DooDaa One") ;
c.gridy = 1 ;
c.gridx = 2 ;
g.setConstraints(fp, c) ;
add(fp) ;
fp = new DooDaaPanel("DooDaa The Second") ;
c.gridy = 2 ;
c.gridx = 2 ;
g.setConstraints(fp, c) ;
add(fp) ;
}
public void setVolts(int vcc, int vpp1, int vpp2)
{
Color c ;
c = vcc < 10 ? Color.gray : vcc < 40 ? Color.green : Color.red ;
leftBlob.setColor(c) ;
c = vpp1 < 10 ? Color.gray : vpp1 < 60 ? Color.green : Color.red ;
midBlob.setColor(c) ;
c = vpp2 < 10 ? Color.gray : vpp2 < 60 ? Color.green : Color.red ;
rightBlob.setColor(c) ;
}
}
class DooDaaPanel extends Panel
{
Blob b ;
TextField t ;
DooDaaPanel(String name)
{
GridBagLayout g = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints() ;
setLayout(g) ;
c.ipadx = 2 ;
c.ipady = 1 ;
b = new Blob(Color.yellow, 10) ;
c.anchor = c.WEST ;
g.setConstraints(b,c) ;
add(b) ;
t = new TextField(name) ;
t.setEditable(false) ;
c.gridx=1 ;
g.setConstraints(t,c) ;
add(t) ;
}
}
class Blob extends Canvas
{
Color colour ;
int size, t;
int xpad = 2 ;
int ypad = 1 ;
public Blob(Color c,int s)
{
colour = c ;
size = s ;
setSize(size+xpad*2+1,size+ypad*2+1) ;
t = size <= 20 ? 2 : 4 ;
}
public void setColor(Color c)
{
colour = c ;
}
public void paint(Graphics g)
{
Color cc = g.getColor() ;
g.setColor(Color.black) ;
g.fillArc(xpad,ypad, size,size,0,360) ;
g.setColor(colour) ;
g.fillArc(xpad+t/2,ypad+t/2, size-t,size-t,0,360) ;
g.setColor(cc) ;
}
}
}
(Review ID: 39357)
======================================================================
- relates to
-
JDK-5050375 Infinit loop in panel layout
-
- Closed
-