2017-10-18 104 views
0

我是新來的鞦韆。我正在使用JFD構建面板,以便每當面板窗口展開或摺疊時,內部內容也應該保持連接到面板並相應地展開或摺疊。如何在父面板展開或摺疊時將面板連接到它的父面板

我一直在IntelliJ上使用JFormDesigner插件來這樣做。請在附加圖像上找到面板的樹形視圖。

我的問題是我應該調查哪個面板的屬性?

也許我無法在詢問這個問題時給你全部細節,但我對所有問題都開放。

這裏是我的代碼:

public class aa extends JPanel 
{ 
    public aa() 
    { 
     initComponents(); 
    } 

    private void createUIComponents() { 
     // TODO: add custom component creation code here 
    } 

    private void initComponents() 
    { 
     // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents 
     DefaultComponentFactory compFactory = DefaultComponentFactory.getInstance(); 
     mSplitPane1 = new JSplitPane(); 
     mPanel1 = new JPanel(); 
     mSeparator1 = compFactory.createSeparator("text"); 
     mLabel6 = new JLabel(); 
     mTextField6 = new JTextField(); 
     mLabel9 = new JLabel(); 
     mTextField9 = new JTextField(); 
     mCheckBox1 = new JCheckBox(); 
     mLabel7 = new JLabel(); 
     mTextField7 = new JTextField(); 
     mLabel10 = new JLabel(); 
     mTextField10 = new JTextField(); 
     mLabel8 = new JLabel(); 
     mTextField8 = new JTextField(); 
     mLabel11 = new JLabel(); 
     mTextField11 = new JTextField(); 

     //======== this ======== 
     setName("this"); 
     setLayout(new FormLayout(
      "default:grow", 
      "fill:default:grow")); 

     //======== mSplitPane1 ======== 
     { 
      mSplitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT); 
      mSplitPane1.setDividerLocation(230); 
      mSplitPane1.setOpaque(false); 
      mSplitPane1.setName("splitPane1"); 

      //======== mPanel1 ======== 
      { 
       mPanel1.setName("panel1"); 
       mPanel1.setLayout(new FormLayout(
        "100dlu, $lcgap, 20dlu, $lcgap, 90dlu, $lcgap, default, $lcgap, 136dlu, $lcgap, 26dlu, $lcgap, 107dlu, $lcgap, default, $lcgap, 40dlu", 
        "6*(default, $lgap), 14dlu")); 

       //---- mSeparator1 ---- 
       mSeparator1.setName("separator1"); 
       mPanel1.add(mSeparator1, CC.xywh(1, 1, 17, 1)); 

       //---- mLabel6 ---- 
       mLabel6.setText("text"); 
       mLabel6.setName("label6"); 
       mPanel1.add(mLabel6, CC.xy(1, 5, CC.RIGHT, CC.DEFAULT)); 

       //---- mTextField6 ---- 
       mTextField6.setName("textField6"); 
       mPanel1.add(mTextField6, CC.xy(5, 5)); 

       //---- mLabel9 ---- 
       mLabel9.setText("text"); 
       mLabel9.setName("label9"); 
       mPanel1.add(mLabel9, CC.xy(9, 5, CC.RIGHT, CC.DEFAULT)); 

       //---- mTextField9 ---- 
       mTextField9.setName("textField9"); 
       mPanel1.add(mTextField9, CC.xy(13, 5)); 

       //---- mCheckBox1 ---- 
       mCheckBox1.setText("text"); 
       mCheckBox1.setName("checkBox1"); 
       mPanel1.add(mCheckBox1, CC.xy(17, 5, CC.RIGHT, CC.DEFAULT)); 

       //---- mLabel7 ---- 
       mLabel7.setText("text"); 
       mLabel7.setName("label7"); 
       mPanel1.add(mLabel7, CC.xy(1, 9, CC.RIGHT, CC.DEFAULT)); 

       //---- mTextField7 ---- 
       mTextField7.setName("textField7"); 
       mPanel1.add(mTextField7, CC.xy(5, 9)); 

       //---- mLabel10 ---- 
       mLabel10.setText("text"); 
       mLabel10.setName("label10"); 
       mPanel1.add(mLabel10, CC.xy(9, 9, CC.RIGHT, CC.DEFAULT)); 

       //---- mTextField10 ---- 
       mTextField10.setName("textField10"); 
       mPanel1.add(mTextField10, CC.xy(13, 9)); 

       //---- mLabel8 ---- 
       mLabel8.setText("text"); 
       mLabel8.setName("label8"); 
       mPanel1.add(mLabel8, CC.xy(1, 13, CC.RIGHT, CC.DEFAULT)); 

       //---- mTextField8 ---- 
       mTextField8.setName("textField8"); 
       mPanel1.add(mTextField8, CC.xy(5, 13)); 

       //---- mLabel11 ---- 
       mLabel11.setText("text"); 
       mLabel11.setName("label11"); 
       mPanel1.add(mLabel11, CC.xy(9, 13, CC.RIGHT, CC.DEFAULT)); 

       //---- mTextField11 ---- 
       mTextField11.setName("textField11"); 
       mPanel1.add(mTextField11, CC.xywh(13, 13, 5, 1)); 
      } 
      mSplitPane1.setTopComponent(mPanel1); 
     } 
     add(mSplitPane1, CC.xy(1, 1)); 
     // JFormDesigner - End of component initialization //GEN-END:initComponents 
    } 

    // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables 
    private JSplitPane mSplitPane1; 
    private JPanel mPanel1; 
    private JComponent mSeparator1; 
    private JLabel mLabel6; 
    private JTextField mTextField6; 
    private JLabel mLabel9; 
    private JTextField mTextField9; 
    private JCheckBox mCheckBox1; 
    private JLabel mLabel7; 
    private JTextField mTextField7; 
    private JLabel mLabel10; 
    private JTextField mTextField10; 
    private JLabel mLabel8; 
    private JTextField mTextField8; 
    private JLabel mLabel11; 
    private JTextField mTextField11; 
    // JFormDesigner - End of variables declaration //GEN-END:variables 
} 

after expansion

before

tree view

+0

這其實就是佈局管理和使用的約束面板添加到佈局。它與IDE或GUI設計器無關。 –

+0

1)爲了更快地獲得更好的幫助,請發佈[MCVE]或[簡短,獨立,正確的示例](http://www.sscce.org/)。 2)以最小尺寸提供ASCII圖形或簡單的GUI圖形佈局圖,並且如果可調整大小,具有更多寬度和高度,則顯示應該如何使用額外空間。 –

回答

0

我不知道是否它會幫助你或沒有,因爲你沒有SSCCE連接,但我會改變你的佈局如下:

setLayout(new FormLayout(
     "default:grow", 
     "fill:default:grow")); 

要:

setLayout(new FormLayout(
     "fill:default:grow", // row must fill all its content 
     "fill:default:grow")); 

另外:

 // change "default" -> to "glue". this allows to make an empty growing column 
     // if you want to make your fields growing, you should make them "fill:default:grow" 
     mPanel1.setLayout(new FormLayout(
       "100dlu, $lcgap, 20dlu, $lcgap, 90dlu, $lcgap, default, $lcgap, 136dlu, $lcgap, 26dlu, $lcgap, 107dlu, $lcgap, default, $lcgap, 40dlu", 
       "6*(default, $lgap), 14dlu")); 

要:

 mPanel1.setLayout(new FormLayout(
       "100dlu, $lcgap, 20dlu, $lcgap, 90dlu, $lcgap, glue, $lcgap, 136dlu, $lcgap, 26dlu, $lcgap, 107dlu, $lcgap, default, $lcgap, 40dlu", 
       "6*(default, $lgap), 14dlu")); 
+0

非常感謝。感謝您的幫助。我必須做出以下更改: 'mPanel1.setLayout(new FormLayout( 「100dlu,$ lcgap,20dlu,$ lcgap,90dlu,$ lcgap,default,$ lcgap,136dlu,$ lcgap,26dlu,$ lcgap,107dlu ,$ lcgap,default,$ lcgap,40dlu,$ lcgap,default:grow「, 」6 *(default,$ lgap),14dlu「));' and 'mPanel1.add(mSeparator1,CC.xywh (1,1,19,1));' 最後不得不添加一個空白列,必須將resize屬性更改爲1。 –