所以我有6个面板,所有面板都使用网格布局.我使用gridbaglayout将它们放在一起,这是我想要的设计

事实证明它变得一团糟"第二个"面板变得更加偏向右边第三个面板被挤压了很多左边,这是一场灾难.这是我的gridbag布局代码
c.gridx = 0; c.gridy = 0;
add (first,c);
c.gridx = 2; //so that the second panel starts from the center and is divided evenly with the first panel
add(second,c);
c.gridx = 0; c.gridy = 1;
add(third,c);
c.gridx = 1;
add(fourth,c);
c.gridx = 2;
add(fifth,c);
c.gridx = 3;
add(sixth,c);
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.
我有一个JPanel,其中包含2个JPanel.位于左侧(左侧)和右侧(rB),我想在右侧JPanel(rB)上添加背景图像.
但我得到的结果是
我想要的结果
public void paintComponent(Graphics g)
{
//this.paintComponent(g);
if(wdimage != null) g.drawImage(wdimage,0,0,800,800,rB); //(image,location x, location y, size x, size y)
}
Run Code Online (Sandbox Code Playgroud)
rB Panel正在阻止图像,我想要的是在JPanel上显示图像,并在JPanel上添加一些jlabels和文本字段,稍后再添加图像.