1
Ich möchte, dass die blaue Komponente die weiße Lücke füllt. Ich habe versucht, die Gridheight = 2 zu verwenden und nichts ist passiert. Ich sehe es so, dass es drei Zellen gibt und ich möchte, dass sich die Komponente in eine vierte Zelle ausdehnt, die nicht vorhanden ist. Wie kann ich es umgehen?Eine Komponente über mehrere Zeilen mit GridBagLayout erstellen
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class GUIFrame extends JFrame
{
public GUIFrame(String title)
{
super(title);
}
public void init()
{
setLayout(new GridBagLayout());
GridBagConstraints gbConstraints = new GridBagConstraints();
DisplayPanel display = new DisplayPanel();
ControlPanel control = new ControlPanel();
GalleryPanel gallery = new GalleryPanel();
gbConstraints.gridx = 0;
gbConstraints.gridy = 0;
gbConstraints.weightx = 0.8;
gbConstraints.weighty = 0.75;
gbConstraints.fill=gbConstraints.BOTH;
add(display,gbConstraints);
gbConstraints.gridx = 1;
gbConstraints.gridy = 0;
gbConstraints.weightx = 0.2;
gbConstraints.weighty = 0.75;
gbConstraints.fill=gbConstraints.BOTH;
add(gallery,gbConstraints);
gbConstraints.gridx = 0;
gbConstraints.gridy = 1;
gbConstraints.weightx = 1;
gbConstraints.weighty = 0.3;
gbConstraints.fill=gbConstraints.BOTH;
add(control,gbConstraints);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(1600,900);
setVisible(true);
}
}
Ich bin mit einem GridBagConstraints Objekt –