不会有什么结果,不过你创建的窗口不会正常显示大大小。 下面是这个函数的解释:) public void pack()Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. If the window and/or its owner are not yet displayable, both are made displayable before calculating the preferred size. The Window will be validated after the preferredSize is calculated. See Also: Component.isDisplayable()
不会有什么结果,只是窗口不能正常显示。下面是这个函数的解释 public void pack() Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. If the window and/or its owner are not yet displayable, both are made displayable before calculating the preferred size. The Window will be validated after the preferredSize is calculated. See Also: Component.isDisplayable()
测试一下下面的几种情况(注意出现窗口的大小)或许对你有所帮助: //1、 Slider frame = new Slider(); frame .setSize(300,300); frame .pack(); frame.setVisible(true); ////////////// //2、 Slider frame = new Slider(); frame .pack(); frame .setSize(300,300); frame.setVisible(true); ////////////////// //3、 Slider frame = new Slider(); frame .setSize(300,300); frame.setVisible(true);////////////然后,再结合 jdk 帮助: Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. If the window and/or its owner are not yet displayable, both are made displayable before calculating the preferred size. The Window will be validated after the preferredSize is calculated. 看看! 供参考!
下面是这个函数的解释:)
public void pack()Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. If the window and/or its owner are not yet displayable, both are made displayable before calculating the preferred size. The Window will be validated after the preferredSize is calculated. See Also:
Component.isDisplayable()
public void pack()
Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. If the window and/or its owner are not yet displayable, both are made displayable before calculating the preferred size. The Window will be validated after the preferredSize is calculated. See Also:
Component.isDisplayable()
//1、
Slider frame = new Slider();
frame .setSize(300,300);
frame .pack();
frame.setVisible(true);
//////////////
//2、
Slider frame = new Slider();
frame .pack();
frame .setSize(300,300);
frame.setVisible(true);
//////////////////
//3、
Slider frame = new Slider();
frame .setSize(300,300);
frame.setVisible(true);////////////然后,再结合 jdk 帮助:
Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. If the window and/or its owner are not yet displayable, both are made displayable before calculating the preferred size. The Window will be validated after the preferredSize is calculated.
看看!
供参考!