gpt4 book ai didi

java - 如何使用 JFrame.pack()?

转载 作者:行者123 更新时间:2023-12-01 22:46:10 24 4
gpt4 key购买 nike

我如何使用pack()以及它的作用是什么?

例如:

//1. Create the frame.
JFrame frame = new JFrame("FrameDemo");

//2. Optional: What happens when the frame closes?
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//3. Create components and put them in the frame.
//...create emptyLabel...
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);

//4. Size the frame. (How does pack() set the frame size???)
frame.pack();

//5. Show it.
frame.setVisible(true);

最佳答案

该方法的行为在文档(javadoc)中指定。

这是 Window.pack 的文档.

Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. The resulting width and height of the window are automatically enlarged if either of dimensions is less than the minimum size as specified by the previous call to the setMinimumSize method.

关于java - 如何使用 JFrame.pack()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25335064/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com