简体   繁体   English

在调整Applet大小之前,JFrame不会显示在JApplet中

[英]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. 我正在创建一个Java applet,并试图向其中添加一个JFrame。 I am calling: 我正在打电话:

add(new MyJFrameSubclass());

But when I launch the application, my JFrame isn't shown until I resize the window. 但是,当我启动该应用程序时,直到调整窗口大小后,我的JFrame才会显示。

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

A simple fix is to add a frame.show(); 一个简单的解决方法是添加一个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之后,我遇到了同样的问题,这似乎有所帮助,该框架是您JFrame的名称。

JFrame and JApplet are both top-level containers . JFrameJApplet都是顶级容器 Instead of trying to have both containers present at once, put your content in a lightweight container such as JPanel ; 不要将您的内容同时放在一个轻量级的容器(例如JPanel ,而不要尝试同时使用这两个容器。 then add that JPanel to either a JFrame (for local use) or a JApplet (for the browser). 然后将该JPanel添加到JFrame (供本地使用)或JApplet (供浏览器使用)中。 This example shows the approach. 示例显示了该方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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