(Apple problem #3311245, 3469613)
This is similar to the Brush Bar applet, except that here the component is not being changed, it is being re-loaded.
This problem was fixed with the Panther (OS 10.3; 1.4.1 MRJ 99) release. Although the original problem this was meant to reproduce persisted in our large applet continued, this is fixed with 1.4.2.
If you have any insights, workarounds or comments about this test page please contact Mickey Segal. A listing of many Java resources is at this link.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class brush_panel extends Applet implements ActionListener, WindowListener {
Frame frame;
Button button;
BoxPanel boxPanelA, boxPanelB;
boolean panelAShowing;
public void init()
{
frame = new Frame("A frame");
frame.setLayout(new GridBagLayout());
frame.setBounds(100, 100, 600, 300);
boxPanelA = new BoxPanel();
boxPanelA.setLayout(new GridBagLayout());
Label panelALabel = new Label("Panel A");
constrain(boxPanelA, panelALabel, 0, 0, 1, 1, GridBagConstraints.WEST, 20, 20, 20, 20,
GridBagConstraints.VERTICAL, 0, 1);
boxPanelB = new BoxPanel();
boxPanelB.setLayout(new GridBagLayout());
Label panelBLabel = new Label("Panel B");
constrain(boxPanelB, panelBLabel, 0, 0, 1, 1, GridBagConstraints.WEST, 20, 20, 20, 20,
GridBagConstraints.VERTICAL, 0, 1);
displayProperPanel();
button = new Button("Change panel");
button.addActionListener(this);
constrain(frame, button, 1, 0, 1, 1, GridBagConstraints.WEST, 0, 20, 0, 0,
GridBagConstraints.NONE, 0, 0);
frame.validate();
frame.show();
frame.addWindowListener(this);
}
void displayProperPanel()
{
if (panelAShowing)
{
frame.remove(boxPanelA);
constrain(frame, boxPanelB, 0, 0, 1, 1, GridBagConstraints.WEST, 0, 0, 0, 0,
GridBagConstraints.NONE, 0, 0);
panelAShowing = false;
}
else
{
frame.remove(boxPanelB);
constrain(frame, boxPanelA, 0, 0, 1, 1, GridBagConstraints.WEST, 0, 0, 0, 0,
GridBagConstraints.NONE, 0, 0);
panelAShowing = true;
}
frame.invalidate();
frame.validate();
}
static final void constrain(Container container, Component component, int grid_x, int grid_y,
int grid_width, int grid_height, int anchor, int topPad, int leftPad, int bottomPad,
int rightPad, int fill, double weightx, double weighty)
{
GridBagConstraints c = new GridBagConstraints();
c.gridx = grid_x;
c.gridy = grid_y;
c.gridwidth = grid_width;
c.gridheight = grid_height;
c.anchor = anchor;
c.insets.top = topPad;
c.insets.left = leftPad;
c.insets.bottom= bottomPad;
c.insets.right = rightPad;
c.fill = fill;
c.weightx = weightx;
c.weighty = weighty;
((GridBagLayout)container.getLayout()).setConstraints(component, c);
container.add(component);
}
public void windowOpened(WindowEvent we){}
public void windowClosed(WindowEvent we){}
public void windowIconified(WindowEvent we){}
public void windowDeiconified(WindowEvent we){}
public void windowActivated(WindowEvent we){}
public void windowDeactivated(WindowEvent we){}
public void windowClosing(WindowEvent we)
{
if (we.getSource() == frame)
{
frame.setVisible(false);
frame.dispose();
}
}
public void paint(Graphics g)
{
g.drawString("A frame should pop up", 10 , 20);
}
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource() == button)
{
displayProperPanel();
}
}
} // END OF Class brush_panel
class BoxPanel extends Panel { // panel with a box around it
int width = 0;
int height = 0;
public void addNotify()
{
super.addNotify();
repaint();
}
public final void paint(Graphics g)
{
width = getSize().width;
height = getSize().height;
g.setColor(Color.black);
g.drawRect(0, 0, width -1, height -1); // out
g.drawRect(1, 1, width -3, height -3); // in
}
} // END OF Class BoxPanel