First set the panel layout to GridBagLayout .
Then create a GridBagConstraints and set the fill to GridBagConstraints.BOTH .
In JLabel set the following properties of the constraint object: gridx = 0, gridy = 0, gridwidth = 2, gridheight = 2, weightx = 1, weighty = 1 .
For JTextField set the following properties for the constraint object: gridx = 0, gridy = 1, gridwidth = 1, gridheight = 1, weightx = 1, weighty = 0 .
For JButton set the following properties for the constraint object: gridx = 1, gridy = 1, gridwidth = 1, gridheight = 1, weightx = 0, weighty = 0 .
source share