2013-04-12 71 views
0

我想知道爲什麼我不能調整我的框架的大小,並調整框架調整大小的所有組件調整大小越來越小。謝謝!!!如何使一個Java swing JFrame正確調整大小

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); 

}

回答

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

甲的FlowLayout一貫尊重添加到它的部件的優選尺寸。

擺脫了「它」面板中,並嘗試只使用

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

一幀的默認佈局是BorderLayout的,這將嘗試增加/減少添加到它的所有組件的大小。