在JOptionPane确认对话框之后,画布的右侧和底部的白条? [英] White bars in the right and bottom sides of a canvas after a JOptionPane confirmDialog?

查看:66
本文介绍了在JOptionPane确认对话框之后,画布的右侧和底部的白条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,使用JOptionPane询问用户应用程序是否应该更新,然后在画布的底部和右侧显示这些白色条.试图删除自动更新的东西,并正常工作.这是我的代码

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. Tried removing the autoupdate thing and works fine. Here's my code

GameUtils.init();
String version = AutoUpdate.checkForUpdates();
if (Double.parseDouble(version) > AutoUpdate.VERSION) {
    AutoUpdate.update(version);            
    JFrame frame = null;

    try
    {
        frame = new JFrame(GameUtils.data.getString("title"));
    } catch (JSONException e)
    {
        e.printStackTrace();
    }

    frame.getContentPane().setPreferredSize(new Dimension(1000, 500));
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.setResizable(false);
    frame.pack();
    frame.setLocationRelativeTo(null);
    GameUtils.instance = new Game(frame);

    frame.addWindowListener(new WindowListener() {
        @Override
        public void windowOpened(WindowEvent e) {

        }

        @Override
        public void windowClosing(WindowEvent e) {
            GameUtils.instance.stop();
            System.exit(0);
        }

        @Override
        public void windowClosed(WindowEvent e) {


        }

        @Override
        public void windowIconified(WindowEvent e) {

        }

        @Override
        public void windowDeiconified(WindowEvent e) {

        }

        @Override
        public void windowActivated(WindowEvent e) {

        }

        @Override
        public void windowDeactivated(WindowEvent e) {

        }
    });
    frame.setVisible(true);
    GameUtils.instance.start();
}

协调系统正常工作 我希望它以这种方式显示

Coordinating system works normally I want it to look this way

推荐答案

我在JFrame中使用setResizable(false)和pack()方法时遇到了与您注意到的问题相同的问题. 此处,您可以找到描述问题的答案,但我没有找不到适合我的解决方案.

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.

在我的应用程序中,如果需要,我使用一种技巧":我检查contentPane的首选宽度是否等于其有效宽度,否则请调用pack()方法.

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.

类似的东西:

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

当然,这不是一个很好的解决方案,但是它对我有用,如果您使用参数来限制pack()应该出现的最大次数,那么您就不必冒险阻止gui.

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

这篇关于在JOptionPane确认对话框之后,画布的右侧和底部的白条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆