简体   繁体   中英

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:

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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