使用 Netbeans,我成功地将一个大小固定的 jpanel 放在另一个 jpanel 中。现在我不能重复它——只能复制它。
我是怎么做的?(或者我应该在另一个 jpanel 中以固定大小将 x 和 ya jpanel 居中)。
结果在代码中有所不同:
工作 - 搜索 .addContainerGap( 并查看下一个不工作:
javax.swing.GroupLayout center3Layout = new javax.swing.GroupLayout(center3);
center3.setLayout(center3Layout);
center3Layout.setHorizontalGroup(
center3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 1064, Short.MAX_VALUE)
.addGroup(center3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(center3Layout.createSequentialGroup()
.addContainerGap(30, Short.MAX_VALUE)
.addComponent(mainPanel3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(30, Short.MAX_VALUE)))
);
center3Layout.setVerticalGroup(
center3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 650, Short.MAX_VALUE)
.addGroup(center3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(center3Layout.createSequentialGroup()
.addContainerGap(23, Short.MAX_VALUE)
.addComponent(mainPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(23, Short.MAX_VALUE)))
);
不工作 - 与上述工作相比,搜索 .addGap。
javax.swing.GroupLayout center2Layout = new javax.swing.GroupLayout(center2);
center2.setLayout(center2Layout);
center2Layout.setHorizontalGroup(
center2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 1073, Short.MAX_VALUE)
.addGroup(center2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(center2Layout.createSequentialGroup()
.addGap(0, 34, Short.MAX_VALUE)
.addComponent(mainPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 35, Short.MAX_VALUE)))
);
center2Layout.setVerticalGroup(
center2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 654, Short.MAX_VALUE)
.addGroup(center2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(center2Layout.createSequentialGroup()
.addGap(0, 25, Short.MAX_VALUE)
.addComponent(mainPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 25, Short.MAX_VALUE)))
);
我已经并排查看了属性等 - 请帮助!:)