【发布时间】:2010-05-20 09:29:25
【问题描述】:
使用 Netbeans,我成功地将一个大小固定的 jpanel 置于另一个 jpanel 中。现在我不能重复了——只能复制它。
我是怎么做的? (或者我应该在另一个 jpanel 中以固定大小的 jpanel 居中 x 和 y)。
结果代码不同:
工作 - 搜索 .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)))
);
我在属性等方面并排查看过 - 请帮助! :)
【问题讨论】:
-
看看 Netbeans 为“工作”文件生成的“表单”文件可能会很有趣。这是 NB 创建的一个 xml 文件,包含您的布局结构。发现其中的实际差异可能更容易(但不能保证)。
标签: java swing layout jpanel netbeans6.8