0

我想知道为什么我不能在下面调整我的框架大小,并且在调整框架大小时让所有组件的大小越来越小。谢谢!!!

public class TPASimulatorGUI extends JFrame{
    JPanel mainPanel = new JPanel();
    BoxLayout layout = new BoxLayout(mainPanel,BoxLayout.Y_AXIS);       
    mainPanel.setLayout(layout);

                // add things to main panel

    JPanel it = new JPanel(new FlowLayout(FlowLayout.LEADING));

    it.add(mainPanel);

    this.getContentPane().add(it);
    this.setSize(new Dimension(1190,770));
    this.setVisible(true);

}

4

1 回答 1

2
JPanel it = new JPanel(new FlowLayout(FlowLayout.LEADING));
it.add(mainPanel);

FlowLayout 始终尊重添加到其中的组件的首选大小。

摆脱“它”面板并尝试使用

//this.getContentPane().add(it);
add(mainPanel);

框架的默认布局是 BorderLayout,它将尝试增加/减少添加到其中的所有组件的大小。

于 2013-04-12T17:37:42.850 回答