【问题标题】:What causes the Jframe to flicker while resizing?是什么导致 Jframe 在调整大小时闪烁?
【发布时间】:2015-03-30 18:26:07
【问题描述】:
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

    }

}

这是一个可以复制粘贴的示例。除了我自己,我不能代表任何人说话,但是当我调整大小时,JFrame 会奇怪地闪烁。有人知道是什么原因造成的吗?

先谢谢你了。

【问题讨论】:

  • jFrames 会自动使用双缓冲吗?

标签: java jframe


【解决方案1】:

听起来像是自动刷新/自动重绘问题。当您拖动 JPane 时,它​​会尝试更新其所有组件的布局,从而导致闪烁。本次讨论应该有解决方案:How to stop the auto-repaint() when I resize the Jframe

【讨论】:

    猜你喜欢
    • 2015-11-23
    • 2019-01-11
    • 1970-01-01
    • 2022-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    相关资源
    最近更新 更多