White bars in the right and bottom sides of a canvas after a JOptionPane confirmDialog?

半腔热情 提交于 2019-12-02 12:51:59
Ansharja

I have the same problem you noticed when i use setResizable(false) and pack() method in a JFrame. Here you can find an answer which describes the problem, but i didn't find a solution that works for me.

In my applications i use a sort of "trick" if needed: i check if the contentPane preferred width is equal to his effective width, if not i recall pack() method.

Something like:

for(int i=0;i<5 && contentPane.getPreferredSize().width!=contentPane.getSize().width;i++) frame.pack();

Of course this isn't a really good solution, but it works for me and if you use a parameter to limit the maximum number of times that pack() should occur, you don't risk to block your gui...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!