-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.1
-
x86
-
windows_95
The test case below illustrates the problem. Try clicking on the radio buttons to add/remove the components in a BorderLayout panel.
For example, initially, all five zones are shown. Click on the Add/Remove North
radio button and both the North and Center zones disappear.
import java.applet.Applet;
import java.awt.*;
public class Test extends Applet
{
static Frame f;
Button btnNorth = new Button ("North");
Button btnSouth = new Button ("South");
Button btnEast = new Button ("East");
Button btnWest = new Button ("West");
Button btnCenter = new Button ("Center");
Checkbox c = new Checkbox ("Add/Remove North");
Checkbox c1 = new Checkbox ("Add/Remove South");
Checkbox c2 = new Checkbox ("Add/Remove East");
Checkbox c3 = new Checkbox ("Add/Remove West");
Checkbox c4 = new Checkbox ("Add/Remove Center");
Panel borderPanel = new Panel ();
Panel chkboxPanel = new Panel ();
public void init ()
{
borderPanel.setLayout (new BorderLayout());
add (btnNorth, "North");
add (btnSouth, "South");
add (btnEast, "East");
add (btnWest, "West");
add (btnCenter, "Center");
chkboxPanel.setLayout (new GridLayout(0,1));
chkboxPanel.add (c);
chkboxPanel.add (c1);
chkboxPanel.add (c2);
chkboxPanel.add (c3);
chkboxPanel.add (c4);
add (borderPanel);
add (chkboxPanel);
}
public void start ()
{
//System.out.println ("layout="+getLayout().toString());
}
public boolean handleEvent (Event e)
{
if (e.target == c)
{
if (c.getState ()) //true => remove ..
remove (btnNorth);
else // false => add
add (btnNorth, "North");
}
if (e.target == c1)
{
if (c1.getState ()) //true => remove ..
remove (btnSouth);
else // false => add
add (btnSouth, "South");
}
if (e.target == c2)
{
if (c2.getState ()) //true => remove ..
remove (btnEast);
else // false => add
add (btnEast, "East");
}
if (e.target == c3)
{
if (c3.getState ()) //true => remove ..
remove (btnWest);
else // false => add
add (btnWest, "West");
}
if (e.target == c4)
{
if (c4.getState ()) //true => remove ..
remove (btnCenter);
else // false => add
add (btnCenter, "Center");
}
return false;
}
public void remove (Button b)
{
BorderLayout lb = (BorderLayout) borderPanel.getLayout();
//lb.removeLayoutComponent(b);
borderPanel.remove (b);
validate ();
}
public void add (Button b, String s)
{
borderPanel.add (b);
BorderLayout lb = (BorderLayout) borderPanel.getLayout();
lb.addLayoutComponent(b, s);
validate ();
}
public static void main (String args [])
{
Test t = new Test ();
f = new Frame ();
f.add (t);
t.init();
f.show ();
f.resize (100,100);
t.start ();
}
}
brent.christian@eng 1999-06-28
For example, initially, all five zones are shown. Click on the Add/Remove North
radio button and both the North and Center zones disappear.
import java.applet.Applet;
import java.awt.*;
public class Test extends Applet
{
static Frame f;
Button btnNorth = new Button ("North");
Button btnSouth = new Button ("South");
Button btnEast = new Button ("East");
Button btnWest = new Button ("West");
Button btnCenter = new Button ("Center");
Checkbox c = new Checkbox ("Add/Remove North");
Checkbox c1 = new Checkbox ("Add/Remove South");
Checkbox c2 = new Checkbox ("Add/Remove East");
Checkbox c3 = new Checkbox ("Add/Remove West");
Checkbox c4 = new Checkbox ("Add/Remove Center");
Panel borderPanel = new Panel ();
Panel chkboxPanel = new Panel ();
public void init ()
{
borderPanel.setLayout (new BorderLayout());
add (btnNorth, "North");
add (btnSouth, "South");
add (btnEast, "East");
add (btnWest, "West");
add (btnCenter, "Center");
chkboxPanel.setLayout (new GridLayout(0,1));
chkboxPanel.add (c);
chkboxPanel.add (c1);
chkboxPanel.add (c2);
chkboxPanel.add (c3);
chkboxPanel.add (c4);
add (borderPanel);
add (chkboxPanel);
}
public void start ()
{
//System.out.println ("layout="+getLayout().toString());
}
public boolean handleEvent (Event e)
{
if (e.target == c)
{
if (c.getState ()) //true => remove ..
remove (btnNorth);
else // false => add
add (btnNorth, "North");
}
if (e.target == c1)
{
if (c1.getState ()) //true => remove ..
remove (btnSouth);
else // false => add
add (btnSouth, "South");
}
if (e.target == c2)
{
if (c2.getState ()) //true => remove ..
remove (btnEast);
else // false => add
add (btnEast, "East");
}
if (e.target == c3)
{
if (c3.getState ()) //true => remove ..
remove (btnWest);
else // false => add
add (btnWest, "West");
}
if (e.target == c4)
{
if (c4.getState ()) //true => remove ..
remove (btnCenter);
else // false => add
add (btnCenter, "Center");
}
return false;
}
public void remove (Button b)
{
BorderLayout lb = (BorderLayout) borderPanel.getLayout();
//lb.removeLayoutComponent(b);
borderPanel.remove (b);
validate ();
}
public void add (Button b, String s)
{
borderPanel.add (b);
BorderLayout lb = (BorderLayout) borderPanel.getLayout();
lb.addLayoutComponent(b, s);
validate ();
}
public static void main (String args [])
{
Test t = new Test ();
f = new Frame ();
f.add (t);
t.init();
f.show ();
f.resize (100,100);
t.start ();
}
}
brent.christian@eng 1999-06-28