jEditorPane as a web browser

2020-02-11 02:28发布

I am creating a web browser in Java. In this browser I am using JEditorPane for Browser Window. I am using "setPage(String url)" method to display the page. The browser can display the page but there are some problems which are as mentioned::

  1. The browser is not displaying the java script.
  2. It is not displaying the Applet.
  3. Brows data does not show in proper way(like as a browser(Show in imagealt text)).

My code is-

JEditorPane editorPane = new JEditorPane();
String url="http://google.co.in";    
editorPane.setEditable(false);
  try {
        editorPane.setPage(url);
  } catch (IOException e) {
      System.err.println("Attempted to read a bad URL: " + url);
  }
}

4条回答
叼着烟拽天下
2楼-- · 2020-02-11 02:50

Have you tried SWT? It uses the systems default browser or I believe you can specify Mozilla or Apple's browser(I'm not an Apple fan and cant think of the name right now). Its not coding it from scratch and they must have another browser installed but in Java I think that's your best option. You can find various libraries that incorporate both Swing and SWT with a simple google search so you don't have to choose between the two.

查看更多
对你真心纯属浪费
3楼-- · 2020-02-11 02:54

The JEditorPane can only render very basic HTML. (Even as of SE6, it only understands HTML 3.2—a standard from 1997!) JEditorPane cannot embed applets or Flash, nor can it interpret JavaScript.

As a matter of fact, JEditorPane was written to be a widget in which to edit rich text (ie. text of varying sizes with simple formatting like boldface and italics), not something to render HTML, CSS, and etc.

You may want to try JDIC's embeddable browser instead.

查看更多
一夜七次
4楼-- · 2020-02-11 03:07

JEditorPane has limited html and css support. It does not support javascript or applets. It is not intended to be used as a web browser. Sun promised a JWebPane that would be closer to a browser, but it has never been released.

If you are really willing to implement a browser in java, join some open source java browser project like Lobo browser. This way you can apply your knowledge in a right direction. There is no point doing it from scratch.

查看更多
Bombasti
5楼-- · 2020-02-11 03:08

JavaFX seems to handle this. Has this been tried?

查看更多
登录 后发表回答