有人能告诉我为什么我的 JList 和 JLabel 不会自动调整大小以填满整个屏幕吗?还有为什么 JButton 不自动调整大小?万分感谢
public class testing extends JFrame {
private String[] testArray = {"apple", "banana", "cat"};
private JPanel firstLayer = new JPanel();
private JPanel secondLayerLeft = new JPanel();
private JPanel secondLayerRight = new JPanel();
private JList<String> leftText = new JList<String>();
private JLabel rightOutput = new JLabel();
private JButton button = new JButton("test button");
public testing(){
firstLayer.setLayout(new BorderLayout());
firstLayer.add(secondLayerLeft, BorderLayout.WEST);
firstLayer.add(secondLayerRight, BorderLayout.EAST);
firstLayer.add(button, BorderLayout.SOUTH);
secondLayerLeft.add(leftText);
leftText.setListData(testArray);
secondLayerRight.add(rightOutput);
rightOutput.setText("testing 12345");
secondLayerLeft.setBorder(new EtchedBorder());
secondLayerRight.setBorder(new EtchedBorder());
this.add(firstLayer);
}
public static void main(String[] args) {
testing gui = new testing();
gui.setSize(700, 800);
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui.setVisible(true);
}
}