开发者

Java AWT applet white screen when resizing window

开发者 https://www.devze.com 2022-12-08 19:26 出处:网络
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.

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().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号