有人能告訴我爲什麼我的JList和JLabel不會自動調整大小以填充整個屏幕?另外爲什麼不通過JButton自動調整大小?謝謝一噸請幫我使用Java中的JFrame和BorderLayout
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);
}
}
我該如何去做一個JList和JLabel伸展來填充整個屏幕並自動調整大小? – user2238529