刚开始使用了
jPanel2.setLayout(new java.awt.BorderLayout());
jPanel2.add(jlblLastRefresh, java.awt.BorderLayout.WEST);
jPanel2.add(jBtnChangeChart, java.awt.BorderLayout.EAST);
但是按钮的高度和jpanel2的高度相同,然后百度了一下,使用
setLayout(null);
setBounds(坐标x,坐标y,长度,高度);
发现还是行不通,于是妥协使用了GroupLayout,发现GroupLayout是万能的,无论多磨复杂的位置都能够实现(按钮在jpanel2中的位置可以慢慢调,比如下面的40)
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jlblLastRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 201, Short.MAX_VALUE)
.addComponent(jBtnChangeChart)
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jlblLastRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)//24
.addComponent(jBtnChangeChart))
.addGap(9, 9, 9))
);