简体   繁体   中英

I have to resize my JFrame for the contents to show up. How can i fix that?

When I run my gui, I have to resize the window for everything to show up. Does someone know what the problem is?

在添加所有组件之后和调用setVisible(true)之前,在JFrame上调用pack()。

setVisible(true);

将所有想要的JComponents添加到JFrame后,对我有所帮助。

创建框架时,请在框架上调用setSize()方法以设置初始起始尺寸。

don't need to add pack() method.

Just add the setSize(int, int) on the end of everything, then it will work well.

and setVisible(true) on next to setSize.

I was also having the same problem.

After making any change on the JFrame view, just recall the setVisible(true) method. It just worked for me.

The setBounds() method will resize and reposition a Window. however you might want to look at the way your components are laid out if pack() isn't working (I believe it relies on minimum/preferred sizes of components).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM