问题
My applet pops up in a browser window and then creates a separate JFrame. I'd like to minimize the original hosting browser window. Can I do it from the applet?
回答1:
You can't minimize a browser window from the Applet or with Javascript. You can try playing around with the Javascript window blur
and focus
to see if you can make them work for you. Communicating with JS should be possible as follows
import netscape.javascript.*;
import java.applet.*;
import java.awt.*;
class MyApplet extends Applet {
public void init() {
JSObject win = JSObject.getWindow(this);
JSObject doc = (JSObject) win.getMember("document");
JSObject loc = (JSObject) doc.getMember("location");
String s = (String) loc.getMember("href"); // document.location.href
win.call("f", null); // Call f() in HTML page
}
}
Code untested and taken from Oracle docs
回答2:
No, you can't do it. Your applet does not gain control over the calling window and therefore can't minimize (or otherwise manipulate) that window.
来源:https://stackoverflow.com/questions/11510661/can-a-java-applet-minimize-its-browser-window