1
與Netbeans我已經成功地在一個其他jpanel中居中固定大小的jpanel。現在我不能重複它 - 只能複製它。我是如何在jpanel中將jpanel與netbeans對中的?
我該怎麼辦? (或者我應該如何在另一個jpanel中將x和y作爲固定大小的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)))
);
我已經在屬性等方面並排尋找 - 請幫助!:)
看到Netbeans爲「工作」文件生成的「表單」文件可能很有趣。這是一個NB創建的xml文件,包含您的佈局結構。可能更容易發現它的實際差異(但不能保證)。 – Gnoupi 2010-05-20 15:59:47