// Create a new GridBagConstraints object GridBagConstraints gbc = new GridBagConstraints(); // Set the gridheight property to 2 to span the component across two rows gbc.gridheight = 2; // Add the component to the container using GridBagLayout and GridBagConstraints container.add(component, gbc);
// Create a new GridBagConstraints object GridBagConstraints gbc = new GridBagConstraints(); // Set the gridheight property to 1 to occupy a single row gbc.gridheight = 1; // Add the component to the container using GridBagLayout and GridBagConstraints container.add(component, gbc);In both examples, the GridBagConstraints class is used from the java.awt package library.