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

前端 未结 1 773
广开言路
广开言路 2021-01-26 07:46

So guys, using a JOptionPane to ask the user if the app should update or not, and after which I get these white bars in the bottom and right sides of my canvas. Tri

相关标签:
1条回答
  • 2021-01-26 08:20

    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...

    0 讨论(0)
提交回复
热议问题