私の質問は、3つのJPanelを私のGrigBadLayoutに拡張する方法です。 私は2枚の写真を追加しました。最初のサンプルが表示され、結果と2番目のサンプルが表示されます。JpanelsをGridBagLayoutに展開する方法
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JPanel;
public class ListMembersView extends JPanel{
JPanel headerPanel;
JPanel containerPanel;
JPanel footerPanel;
public ListMembersView(){
initComponents();
initLayout();
}
private void initComponents(){
this.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255),5));
headerPanel = new JPanel();
headerPanel.setBackground(Color.red);
containerPanel = new JPanel();
containerPanel.setBackground(Color.yellow);
footerPanel = new JPanel();
footerPanel.setBackground(Color.blue);
}
private void initLayout(){
this.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
/*Not expand JPanel?*/
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx=0; c.gridy=0;
this.add(headerPanel,c);
c.gridx=0; c.gridy=1;
c.gridwidth = 3;
this.add(containerPanel,c);
c.gridx=0; c.gridy=2;
this.add(footerPanel,c);
}
}
私の結果は次のとおりです。
私はそのようになりたいと思います:
ありがとう@luka !!!!!! – Arkhan6