java桌面浏览器弹出窗口
我使用下面的代码在默认系统浏览器中启动网页:
String url = "http://www.google.com";
java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
但是我希望我的网页显示在给定大小(高度)的弹出浏览器窗口中,就像我们在 javascript 中使用 Window 对象所做的那样。
有没有办法可以从java控制默认浏览器并要求它打开给定大小的弹出窗口?
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 web 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我可以想到两种方法来解决这个问题:
JEditorPane
。饱受诟病的编辑器窗格并不适合现实世界的浏览,但可以处理各种网站,并且它随着每个版本的发布而不断改进(无论如何,大多数时候)。There are two ways I can think of to approach this problem:
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).在纯 Java 中没有办法做到这一点。
如果您确实需要这样做,您将需要某种方法来找出用户的默认浏览器是什么。然后启动,您将需要使用 System.exec 启动浏览器实例,并提供适当的命令行参数。
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.有一个很好的项目 http://browserlaunch2.sourceforge.net/
您调用一个新的浏览器窗口,如下所示。但是它可能不提供设置窗口高度和宽度的选项。
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.