开发者

java Desktop Browser popup window

I use the below code to launch a web page in default system browser:

String url = "http://www.google.com"; 

java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));

however i want my we开发者_Go百科b page to be displayed in a popup browser window with a given size (with,height) like we can do in javascript with Window Object.

is there a way i can control from java the default browser and ask it to open a popup window with a given size?


There are two ways I can think of to approach this problem:

  1. Instead of going directly to the target URL, open an intermediate URL like http://our.com/bouce.html?url=google.com&w=400&h=300 Then bounce.html uses JavaScript to open url @ w X h.
  2. Use a JEditorPane. The much maligned editor pane is not ideal for real world browsing, but can deal with a variety of sites, and it is improving with each release (most of the time, anyway).


There is no way to do this in pure Java.

If you really need to do this, you will need some way to find out what the user's default browser is. Then launch you will need to launch a browser instance using System.exec, supplying the appropriate command line arguments.


there is this good project http://browserlaunch2.sourceforge.net/

you invoke a new browser window like below. however it probably doesn't offer option for setting window height and width.

BrowserLauncher browser =new BrowserLauncher();
                browser.setNewWindowPolicy(true);
                browser.openURLinBrowser(url);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜