简体   繁体   中英

JFrame not showing up in JApplet until applet is resized

I am creating a Java applet, and I am trying to add a JFrame to it. I am calling:

add(new MyJFrameSubclass());

But when I launch the application, my JFrame isn't shown until I resize the window.

这可能只是一个基本建议,但是坚持使用validate()repaint()有时可以解决看似复杂的问题。

A simple fix is to add a frame.show(); after you add your JFrame, I had the same issue and this seemed to help, the frame being the name of your JFrame.

JFrame and JApplet are both top-level containers . Instead of trying to have both containers present at once, put your content in a lightweight container such as JPanel ; then add that JPanel to either a JFrame (for local use) or a JApplet (for the browser). This example shows the approach.

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