Re: Javas GridBagLayout does not display an (extended) Canvas (AWT / Java 1.4)
Thanks alot, that's it! I do post my fully functional skeleton here to
ease others attempts and I hope that this is not messing up to you.
Take care
Christian
import java.awt.*;
import java.awt.event.*;
public class PaintCanvas extends Frame {
public PaintCanvas() {
GridBagLayout layout = new GridBagLayout();
this.setLayout(layout);
this.setSize(150, 200);
this.setLocation(100, 100);
this.setBackground(Color.gray);
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.BOTH;
constraints.gridx = 0;
constraints.gridy = 0;
// setting these weightx and weighty supersedes
// overriding getPreferredSize() in MyCanvas
constraints.weightx = 1;
constraints.weighty = 1;
MyCanvas canvas = new MyCanvas();
canvas.setBackground(Color.black);
this.add(canvas, constraints);
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.gridx = 0;
constraints.gridy = 1;
// setting these weightx and weighty supersedes
// overriding getPreferredSize() in MyCanvas
constraints.weightx = 1;
constraints.weighty = 0;
Button button = new Button("GridBagLayout is great");
this.add(button, constraints);
}
class MyCanvas extends Canvas {
}
public static void main (String argv[]) {
PaintCanvas painter = new PaintCanvas();
painter.addWindowListener(new WindowAdapter()
{
public void windowClosing (WindowEvent e) {
System.exit (0);
}
});
painter.setVisible (true);
}
}