Components in GridLayout wit JPanel fills the grid incorrectly
问题 I am trying to prevent the GridLayout in a JPanel from filling the cells entirely and ignoring any setSize of the components i am using this code: import javax.swing.*; import java.awt.*; public class GrideComponents{ public static void main(String[] args) { JFrame frame = new JFrame("Laying Out Components in a Grid"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(5,2,0,0)); panel.add(new JLabel("Enter name")); JTextField a = new JTextField(5);