0
問題用下面的代碼是,它是在半分裂MenuPane
而不是所期望的10%至90%的JPanel GridBagLayout的未對準的垂直對象
TitlePane
和ControlPane
只是JPanels。
public class MenuPane extends JPanel {
public MenuPane(int width, int height){
setSize(width, height);
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.weightx = 0.0d;
c.weighty = 0.1d;
add(new TitlePane(this.getWidth(), (int) (this.getHeight()*c.weighty)), c);
c.gridx = 0;
c.gridy = 1;
c.weightx = 0.0d;
c.weighty = 0.9d;
add(new ControlPane(this.getWidth(), (int) (this.getHeight()*c.weighty)), c);
}
}
將首選大小設置工作!謝謝! – MichaelMitchell