简体   繁体   中英

Java AWT applet white screen when resizing window

I have a java applet built using awt.

I draw some text on a panel object and everything goes fine. but when resizing the windows all the text disappears.

this behaviour is different among different jvms and platforms.

moving to swing isn't a possible option, because we have to maintain compatiblty with Microsoft JVM.

You must override update(Graphics g) and render your text in there. This method will be called when the window needs to be redrawn.

Without seeing your code, we have to guess, but is it possible that your text drawing is not being done in a paint() method? Read this for details on how AWT painting works.

Try attaching a ComponentListener which then calls paint() from within componentResized().

Something like:

class MyPanel extents Panel implements ComponentListner {
    public MyPanel() {
        addComponentListener(this);
    }
    public void componentResized(ComponentEvent e) {
        paint(getGraphics());
    }
}

Update: you should probably call 'repaint()' rather than directly invoking paint().

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