理论上bt1和bt2应该是左对齐的呀,为什么会出现这样的情况?
请看代码:
package testgui;
import javax.swing.*;
public class TestGUI {
JFrame jf = new JFrame();
JButton bt1 = new JButton("bt1");
JButton bt2 = new JButton("bt2");
Box box1 = Box.createHorizontalBox();
Box box2 = Box.createVerticalBox();
public void init(){
box1.add(bt1);
box2.add(box1);
box2.add(bt2);
jf.add(box2);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.pack();
jf.setLocationRelativeTo(null);
jf.setVisible(true);
}
public static void main(String[] args) {
new TestGUI().init();
}
}