Hallo,
habe mir gerade das Tutorial von Sun zum GBL durchgelesen, und nun einen einfachen Test gemacht. Leider tut er überhaupt nicht das, was ich wollte. Hier das KSKB:
Was ich will ist: "top" soll die ganze obere Hälfte des Frames einnehmen, und "left" und "big" teilen sich die untere Hälfte. Was hab ich falsch gemacht?
thx
habe mir gerade das Tutorial von Sun zum GBL durchgelesen, und nun einen einfachen Test gemacht. Leider tut er überhaupt nicht das, was ich wollte. Hier das KSKB:
Java:
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MyFrame extends JFrame {
public MyFrame(String title) {
super(title);
JPanel top = new JPanel();
top.setBackground(Color.ORANGE);
JPanel left = new JPanel();
left.setBackground(Color.GREEN);
JPanel big = new JPanel();
big.setBackground(Color.BLUE);
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
setLayout(new GridLayout(2,2));
c.gridwidth = 2;
c.gridheight = 1;
c.gridx = 0;
c.gridy = 0;
add(top,c);
c.gridwidth = 1;
c.gridheight = 1;
c.gridx = 0;
c.gridy = 1;
add(left,c);
c.gridwidth = 1;
c.gridheight = 1;
c.gridx = 1;
c.gridy = 1;
add(big,c);
pack();
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
final MyFrame frame = new MyFrame("GridBagDemo");
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
frame.setVisible(true);
}
});
}
}
Was ich will ist: "top" soll die ganze obere Hälfte des Frames einnehmen, und "left" und "big" teilen sich die untere Hälfte. Was hab ich falsch gemacht?
thx