What causes the Jframe to flicker while resizing?

拜拜、爱过 提交于 2020-01-26 01:49:50

问题


public class AspectRatio extends JFrame implements ComponentListener{

    public AspectRatio() {
        setSize(100, 100);
        setVisible(true);
        addComponentListener(this);
    }

    public static void main(String[] args){
        new AspectRatio();
    }

    @Override
    public void componentHidden(ComponentEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void componentMoved(ComponentEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void componentResized(ComponentEvent e) {
        int i = Math.max(getWidth(), getHeight());
        setSize(i, i);

    }

    @Override
    public void componentShown(ComponentEvent e) {
        // TODO Auto-generated method stub

    }

}

Here is an example you can copy paste. Im cant speak for anyone but myself, but when i resize, the JFrame flickers wierdly. Does someone know what causing this?

Thank you in advanced.


回答1:


Sounds like an auto-refresh/auto-repaint issue. As you drag the JPane, it tries to update layout of all of its components, causing a flickering. This discussion should have the solution: How to stop the auto-repaint() when I resize the Jframe



来源:https://stackoverflow.com/questions/29353493/what-causes-the-jframe-to-flicker-while-resizing

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