Hallo,

wir versuchen seit einiger Zeit ein GridBagLayout zu erstellen. Soweit funktioniert das auch, nur die Mengenmäßige Aufteilung geht nicht.
Hier erstmal unser Code:

Code java:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//GridBagLayout
        GridBagLayout layout = new GridBagLayout();
        contentPane = fenster.getContentPane();
        contentPane.setLayout(layout);
        
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.weightx = 1.0;
        constraints.weighty = 1.0;
        constraints.fill = GridBagConstraints.BOTH;
        
        JPanel p1 = new JPanel();
        JPanel p2 = new JPanel();
        Border etched = BorderFactory.createEtchedBorder();
        Border titled = BorderFactory.createTitledBorder(etched," Ein Titel ");
        p1.setBorder(titled);
        p2.setBorder(titled);
        JButton button = new JButton("Hallo");
        JButton button1 = new JButton("Hallo");
        //add(componente,constraints,gridx,gridy,gridwidth,gridheight,contentPane)
        fenster.add(p1,constraints,0,0,1,3,contentPane);
        fenster.add(p2,constraints,1,0,2,2,contentPane);
        constraints.fill = GridBagConstraints.NONE;
        constraints.anchor = GridBagConstraints.SOUTH;
        constraints.insets = new Insets(5,5,5,5);
        fenster.add(button,constraints,2,2,1,1,contentPane);
        fenster.add(button1,constraints,1,2,1,1,contentPane);

Unsere Frage ist nun: Warum ist das Panel2 nur über zwei Zeilen ausgedehnt, und nicht wie angegeben über drei? Zwischen den zwei Buttons und dem Panel hat es den Anschein, dass eine Zeile dazwischen frei ist. Wo liegt unser Denkfehler?

Danke schonmal im Voraus!