我是新手。我正在使用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
}
答案 0 :(得分: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"));