我正在尝试使用 GridLayout(7,2) 创建面板
membersPanel = new JPanel(new GridLayout(7,2));
但是,当我添加组件(标签、组合框、文本字段等)时,组件会显示在 3 列中,如下所示:
我尝试将列数更改为 1 甚至 0,但面板保持不变。我能做些什么?
编辑:
这里有更多代码:
p1 = new JPanel();
membersPanel = new JPanel(new GridLayout(7,0));
resourcesLabel = new JLabel("Resources");
membersPanel.add(resourcesLabel);
emptyLabel5 = new JLabel("");
membersPanel.add(emptyLabel5);
emptyLabel6 = new JLabel("");
membersPanel.add(emptyLabel6);
comboBoxResource = new JComboBox(configs.XMLreaderDOM4J.readResourceID());
membersPanel.add(comboBoxResource);
slider1 = new SliderWithTextField(1,10);
textSli1 = new TextFieldFromSlider(this, slider1);
slider1.setTextField(textSli1);
slider1.setValue(1);
membersPanel.add(slider1);
membersPanel.add(textSli1);
emptyLabel2 = new JLabel();
membersPanel.add(emptyLabel2);
addButton1 = new JButton("Add");
addButton1.addActionListener(new TrataEvento());
membersPanel.add(addButton1);
agregator1Label = new JLabel("Agretagor1");
membersPanel.add(agregator1Label);
comboBoxAgregator1 = new JComboBox(configs.XMLreaderDOM4J.readAgregator1ID());
membersPanel.add(comboBoxAgregator1);
slider2 = new SliderWithTextField(1,10);
textSli2 = new TextFieldFromSlider(this, slider2);
slider2.setTextField(textSli2);
slider2.setValue(1);
membersPanel.add(slider2);
membersPanel.add(textSli2);
addButton2 = new JButton("Add");
addButton2.addActionListener(new TrataEvento());
membersPanel.add(addButton2);
emptyLabel3 = new JLabel();
membersPanel.add(emptyLabel3);
agregator0Label = new JLabel("Agregator0");
membersPanel.add(agregator0Label);
comboBoxAgregator0 = new JComboBox(configs.XMLreaderDOM4J.readAgregator0ID());
membersPanel.add(comboBoxAgregator0);
slider3 = new SliderWithTextField(1,10);
textSli3 = new TextFieldFromSlider(this, slider3);
slider3.setTextField(textSli3);
slider3.setValue(1);
membersPanel.add(slider3);
membersPanel.add(textSli3);
addButton3 = new JButton("Add");
addButton3.addActionListener(new TrataEvento());
membersPanel.add(addButton3);
emptyLabel4 = new JLabel();
membersPanel.add(emptyLabel4);
p1.add(membersPanel);