首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在JFrame中打开网页地址?

如何在JFrame中打开网页地址?
EN

Stack Overflow用户
提问于 2014-09-23 19:29:28
回答 1查看 1.3K关注 0票数 0

所以我有这段代码来创建一个JFrame:

代码语言:javascript
复制
/* FrameDemo.java requires no other files. */
public class bot {
    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("FrameDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JLabel emptyLabel = new JLabel("");
        emptyLabel.setPreferredSize(new Dimension(400, 400));
        frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);

        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();

             }
        });
     }
 }

我有以下代码来打开一个网页URL:

代码语言:javascript
复制
public class fun {
    public static void main(String[] a) {
        try {
            URI uri = new URI("www.google.lt");
            Desktop desktop = null;
            if (Desktop.isDesktopSupported()) {
                desktop = Desktop.getDesktop();
            }
            if (desktop != null)
                desktop.browse(uri);
        } catch (IOException ioe) { 

            ioe.printStackTrace();
        } catch (URISyntaxException use) {
            use.printStackTrace();
        }
    }
}

如何连接这些代码?并使网页出现在JFrame中?也许在php中有类似的命令include?

EN

回答 1

Stack Overflow用户

发布于 2014-09-24 01:07:05

使用javafx组件库(现在包含在Java中)的WebView组件并将其包装在JFXPanel中,以便可以在您的Swing UI中使用它。

或者,尝试使用来自TeamDev的商业jxBrowser组件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25993951

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档