java 多个 panel_java – 如何并排放置两个jpanel

  • Post author:
  • Post category:java

我试着把两个jpanels并排放在一起,但在这一刻我不能做我想要的

我有这个代码,

this.videoPanel= new JPanel();

this.videoPanel.setBackground(new Color(102, 102, 102));

this.videoPanel.setPreferredSize(new Dimension(320, 240));

this.videoPanel.setLayout(new BoxLayout(this.videoPanel, 1));

GroupLayout layout = new GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)

.addComponent(this.videoPanel, 10, 400, 500)));

layout.setVerticalGroup(

layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)

.addComponent(this.videoPanel, 10, 400, 500)));

pack();

`

我试着再放一个jpanel:

this.videoPanel1.setBackground(new Color(102, 102, 102));

this.videoPanel1.setPreferredSize(new Dimension(320, 240));

this.videoPanel1.setLayout(new BoxLayout(this.videoPanel1, 2));

GroupLayout layout = new GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)

.addComponent(this.videoPanel1, 10, 400, 500)

.addComponent(this.videoPanel, 10, 400, 500)));

layout.setVerticalGroup(

layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)

.addComponent(this.videoPanel1, 10, 400, 500)

.addComponent(this.videoPanel, 10, 400, 500)));

pack();

此代码不起作用,也不会出错.


版权声明:本文为weixin_33547353原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。