Java tutorial
import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JButton; import javax.swing.JFrame; public class Main { public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); GridBagLayout gbl = new GridBagLayout(); frame.setLayout(gbl); JButton component = new JButton("1"); frame.add(component); frame.add(new JButton("2")); gbl.layoutContainer(frame); GridBagConstraints gbc = new GridBagConstraints(); // Make the component on stretchable gbc.fill = GridBagConstraints.NONE; gbl.setConstraints(component, gbc); frame.add(component); frame.pack(); frame.setVisible(true); } }