How do you open web pages in Java?

后端 未结 6 1483
庸人自扰
庸人自扰 2021-02-13 04:19

Is there a simple way to open a web page within a GUI\'s JPanel?

If not, how do you open a web page with the computer\'s default web browser?

I am hoping for so

6条回答
  •  攒了一身酷
    2021-02-13 04:40

    haven't tried it at all, but the cobra HTML parser and viewer from the lobo browser, a browser writen in pure java, may be what you're after. They provide sample code to set up an online html viewer:

    import javax.swing.*;
    import org.lobobrowser.html.gui.*;
    import org.lobobrowser.html.test.*;
    
    public class BareMinimumTest {
      public static void main(String[] args) throws Exception {
        JFrame window = new JFrame();
        HtmlPanel panel = new HtmlPanel();
        window.getContentPane().add(panel);
        window.setSize(600, 400);
        window.setVisible(true);
        new SimpleHtmlRendererContext(panel, new SimpleUserAgentContext())
        .navigate("http://lobobrowser.org/browser/home.jsp");
      }
    }
    

提交回复
热议问题