Java tutorial
import java.awt.Color; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JPanel; public class Main extends JFrame { public Main() { this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.NORTH; gbc.weighty = 0.0; JPanel one = new JPanel(); one.setPreferredSize(new Dimension(200, 200)); one.setBorder(BorderFactory.createLineBorder(Color.BLACK)); JPanel two = new JPanel(); two.setPreferredSize(new Dimension(200, 200)); two.setBorder(BorderFactory.createLineBorder(Color.BLACK)); this.add(one, gbc); gbc.gridy = 1; gbc.weighty = 0.0; gbc.fill = GridBagConstraints.VERTICAL; this.add(two, gbc); this.pack(); this.setVisible(true); } public static void main(String[] args) { new Main(); } }