import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JButton; import javax.swing.JFrame; public class MainWindow extends JFrame { JButton button1 = new JButton("gomb1"); JButton button2 = new JButton("gomb2"); JButton button3 = new JButton("gomb3"); JButton button4 = new JButton("gomb4"); JButton button5 = new JButton("gomb5"); GridBagLayout layout = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); public MainWindow() { this.setLayout(new GridBagLayout()); this.c.fill = GridBagConstraints.HORIZONTAL; this.c.gridx = 0; this.c.gridy = 0; this.add(button1, c); this.c.gridx = 1; this.c.gridy = 0; this.add(button2, c); this.c.gridx = 2; this.c.gridy = 0; this.add(button3, c); this.c.gridx = 0; this.c.gridy = 1; this.c.gridwidth = 3; this.add(button4, c); this.c.gridx = 0; this.c.gridy = 2; this.c.gridwidth = 3; this.c.ipady = 40; this.add(button5, c); this.setTitle("GridBagLayout"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.pack(); this.setVisible(true); } }