简体   繁体   中英

Java - How do I get a live preview of a JPanel?

I am using the following function to get an initial screenshot of a JPanel. How would I set it up to get a live preview of a JPanel?

private static BufferedImage createImage(JPanel panel) {
    int w = 800;
    int h = 550;
    BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = bi.createGraphics();
    panel.paint(g);
    return bi;
}

If you use Eclipse as your IDE, there is an awesome plugin called WindowBuilder. It's a drag'n'drop plugin for making GUI's. If you open a existing JPanel class with it, you can see your panel live, without running any code.

Link: https://eclipse.org/windowbuilder/

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