0
我有一個具有GridBagLayout作爲佈局的JDialog。它包含一個JPanel孩子,他也有一個GridBagLayout作爲佈局。父級包含其他字段,每個字段分爲兩列(標籤 - 編輯器)。孩子包含幾個字段,每個字段分成三列(標籤 - 編輯器 - 標籤)。我希望孩子和父母的第一列對齊在一起。這是它的外觀現在:嵌套的GridBagLayout - 如何將孩子的列與父列對齊
父相關代碼:
GridBagConstraints contrainte = new GridBagConstraints();
Insets insetsLabel = new Insets(0, 0, 0, 0);
Insets insetsChampsEdit = new Insets(0, 10, 0, 0);
contrainte.ipady = 10;
contrainte.gridx = 0;
contrainte.gridy = 1;
contrainte.fill = GridBagConstraints.HORIZONTAL;
contrainte.gridwidth = 1;
this.add(this.m_lblPremierDepart, contrainte);
contrainte.gridx = 1;
contrainte.insets = insetsChampsEdit;
this.add(this.m_timePicker, contrainte);
contrainte.gridx = 0;
contrainte.gridy = 2;
contrainte.insets = insetsLabel; // reset insets
contrainte.gridwidth = 3;
this.add(this.m_panneauDistribution, contrainte);
contrainte.gridy = 3;
contrainte.gridwidth = 1;
this.add(this.m_lblNbMaxVehicules, contrainte);
contrainte.gridx = 1;
contrainte.insets = insetsChampsEdit;
this.add(this.m_spinNbMaxVehicules, contrainte);
兒童相關代碼:
GridBagConstraints contrainte = new GridBagConstraints();
Insets insetsLabel = new Insets(0, 0, 0, 0);
Insets insetsChampsEdit = new Insets(0, 10, 0, 0);
contrainte.ipady = 10;
contrainte.gridx = 0;
contrainte.gridy = 0;
contrainte.fill = GridBagConstraints.HORIZONTAL;
this.add(this.m_lblPlusPetit, contrainte);
contrainte.gridx = 1;
contrainte.insets = insetsChampsEdit;
this.add(this.m_spinPlusPetit, contrainte);
contrainte.gridx = 2;
this.add(new JLabel("minute(s)"), contrainte);
contrainte.gridx = 0;
contrainte.gridy = 1;
contrainte.insets = insetsLabel; // reset insets
this.add(this.m_lblMoyen, contrainte);
contrainte.gridx = 1;
contrainte.insets = insetsChampsEdit;
this.add(this.m_spinMoyen, contrainte);
contrainte.gridx = 2;
this.add(new JLabel("minute(s)"), contrainte);
contrainte.gridx = 0;
contrainte.gridy = 2;
contrainte.insets = insetsLabel; // reset insets
this.add(this.m_lblPlusGrand, contrainte);
contrainte.gridx = 1;
contrainte.insets = insetsChampsEdit;
this.add(this.m_spinPlusGrand, contrainte);
contrainte.gridx = 2;
this.add(new JLabel("minute(s)"), contrainte);
有沒有一種方法,以獲得與GridBagLayout的期望的行爲?