简体   繁体   English

从另一个类刷新jframe

[英]Refresh a jframe from another class

I want to refresh(repaint) a jframe if an event in other class occurred, I use some thing like code below but somethimes this code didn't work: 如果发生其他类中的事件,我想刷新(重画)jframe,我使用下面的代码之类的东西,但是某些代码无法正常工作:

static Container container;
public FrameConstractor()
{
    ...
    container = getContentPane();
    ...
}

public static void refreshMethod()
{
    container.repaint();
}

and I call refresh method when my event occurred; 当事件发生时我调用刷新方法; but this code repaint the frame for me some times and some times didn't do any thing! 但是这段代码为我重新绘制了框架,有时却什么也没做!

I think your problem can be solved by changing refreshMethod to: 我认为您可以通过将refreshMethod更改为:

public static void refreshMethod()
{
    container.invalidate();
    container.validate();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM