public class MyTest extends JFrame { public static void main(String[] args) {
MyTest test = new MyTest();
JPanel p = new JPanel();
p.setLayout(new SpringLayout()); //把这句注释掉,按钮就能正常显示
p.add(new JButton("你好"));
test.setContentPane(p);
test.pack();
test.setLocationRelativeTo(null);
test.setVisible(true);
}}上述代码采用了Springlayout布局,程序运行的结果是,窗口实际大小为0,按钮看不到,只有手动将窗口调大之后才能看到按钮。
如果注释掉springlayout,那么按钮就能正常显示这是springlayout的bug吗?
MyTest test = new MyTest();
JPanel p = new JPanel();
p.setLayout(new SpringLayout()); //把这句注释掉,按钮就能正常显示
p.add(new JButton("你好"));
test.setContentPane(p);
test.pack();
test.setLocationRelativeTo(null);
test.setVisible(true);
}}上述代码采用了Springlayout布局,程序运行的结果是,窗口实际大小为0,按钮看不到,只有手动将窗口调大之后才能看到按钮。
如果注释掉springlayout,那么按钮就能正常显示这是springlayout的bug吗?
Depending on the constraints you use, you may also need to set the size of the container explicitly.