FlowLayout 在之前的组件下添加
FlowLayout add under previous components
我正在尝试向 flowLayout
中的 JPanel
添加一些组件。
JPanel panelPrincipal = new JPanel();
principale.getContentPane().add(panelPrincipal, BorderLayout.CENTER);
panelPrincipal.setLayout(new BorderLayout(0, 0));
JPanel panelDynamique = new JPanel();
JScrollPane jScrollPane = new JScrollPane(panelDynamique);
panelPrincipal.add(jScrollPane, BorderLayout.CENTER);
if(this.getNbAppFor(champs.get(6)) > 0) {
JLabel lblMAJ = new JLabel(champs.get(6));
panelDynamique.add(lblMAJ);
panelDynamique.add(new JSeparator());
JPanel panelMAJ = new JPanel();
panelMAJ.setLayout(new GridLayout(this.getNbAppFor(champs.get(6))/2, 2));
panelDynamique.add(panelMAJ);
}
if(this.getNbAppFor(champs.get(7)) > 0) {
JLabel lblDispo = new JLabel(champs.get(7));
panelDynamique.add(new JSeparator());
JPanel panelDispo = new JPanel();
panelDispo.setLayout(new GridLayout(this.getNbAppFor(champs.get(7))/2, 2));
panelDynamique.add(panelDispo);
}
这是核心构建,但它看起来不像我预期的那样。
我说明了我正在尝试做的事情:
如何将组件添加到上一个组件下的下一个 "row" 中的 FlowLayout
?我怎样才能让我的分隔符填满 Container
的宽度?
根据您的图纸,但未使用 FlowLayout。
package testp;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
public class LayTest {
public static void main(String[] args) {
JPanel p = new JPanel();
p.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.anchor = GridBagConstraints.WEST;
c.weightx = 1;
p.add(new JLabel("Mide a jour"), c);
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 1;
c.fill = GridBagConstraints.HORIZONTAL;
p.add(new JSeparator(), c);
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 2;
c.weighty = 1;
c.fill = GridBagConstraints.HORIZONTAL;
p.add(new JPanel(), c);
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 3;
c.fill = GridBagConstraints.HORIZONTAL;
p.add(new JSeparator(), c);
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 4;
c.anchor = GridBagConstraints.WEST;
p.add(new JLabel("Disponsible"), c);
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 5;
c.fill = GridBagConstraints.HORIZONTAL;
p.add(new JSeparator(), c);
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 6;
c.weighty = 1;
p.add(new JPanel(), c);
JFrame f = new JFrame();
f.setSize(300, 400);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(p);
f.setVisible(true);
}
}
你可能会觉得有用
oracle
我正在尝试向 flowLayout
中的 JPanel
添加一些组件。
JPanel panelPrincipal = new JPanel();
principale.getContentPane().add(panelPrincipal, BorderLayout.CENTER);
panelPrincipal.setLayout(new BorderLayout(0, 0));
JPanel panelDynamique = new JPanel();
JScrollPane jScrollPane = new JScrollPane(panelDynamique);
panelPrincipal.add(jScrollPane, BorderLayout.CENTER);
if(this.getNbAppFor(champs.get(6)) > 0) {
JLabel lblMAJ = new JLabel(champs.get(6));
panelDynamique.add(lblMAJ);
panelDynamique.add(new JSeparator());
JPanel panelMAJ = new JPanel();
panelMAJ.setLayout(new GridLayout(this.getNbAppFor(champs.get(6))/2, 2));
panelDynamique.add(panelMAJ);
}
if(this.getNbAppFor(champs.get(7)) > 0) {
JLabel lblDispo = new JLabel(champs.get(7));
panelDynamique.add(new JSeparator());
JPanel panelDispo = new JPanel();
panelDispo.setLayout(new GridLayout(this.getNbAppFor(champs.get(7))/2, 2));
panelDynamique.add(panelDispo);
}
这是核心构建,但它看起来不像我预期的那样。
我说明了我正在尝试做的事情:
如何将组件添加到上一个组件下的下一个 "row" 中的 FlowLayout
?我怎样才能让我的分隔符填满 Container
的宽度?
根据您的图纸,但未使用 FlowLayout。
package testp;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
public class LayTest {
public static void main(String[] args) {
JPanel p = new JPanel();
p.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.anchor = GridBagConstraints.WEST;
c.weightx = 1;
p.add(new JLabel("Mide a jour"), c);
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 1;
c.fill = GridBagConstraints.HORIZONTAL;
p.add(new JSeparator(), c);
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 2;
c.weighty = 1;
c.fill = GridBagConstraints.HORIZONTAL;
p.add(new JPanel(), c);
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 3;
c.fill = GridBagConstraints.HORIZONTAL;
p.add(new JSeparator(), c);
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 4;
c.anchor = GridBagConstraints.WEST;
p.add(new JLabel("Disponsible"), c);
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 5;
c.fill = GridBagConstraints.HORIZONTAL;
p.add(new JSeparator(), c);
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 6;
c.weighty = 1;
p.add(new JPanel(), c);
JFrame f = new JFrame();
f.setSize(300, 400);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(p);
f.setVisible(true);
}
}
你可能会觉得有用 oracle