这个问题的答案的问题是,你不应该使用
BorderLayout(这在Jframe默认情况下使用),而是使用GridLayout。这样
您就可以将添加
JLabels到
Jframe。一个示例如下所示:
EventQueue.invokeLater(() -> { Jframe frame = new Jframe("Stackoverflow | Question"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setSize(300, 300); frame.setLocationRelativeTo(null); // This is the important line. This will Change the layout to a GridLayout. frame.setLayout(new GridLayout(4, 1)); frame.add(new JLabel("0-29")); frame.add(new JLabel("30-39")); frame.add(new JLabel("40-69")); frame.add(new JLabel("70-100")); frame.setVisible(true);});


