74

Is there a way to embed a browser in Java? more specifically, is there a library that can emulate a browser?

mehdi
  • 912
  • 7
  • 20
Ande Turner
  • 7,096
  • 19
  • 80
  • 107
  • [JxBrowser](http://www.teamdev.com/jxbrowser) library provides Swing/JavaFX lightweight component based on the latest Chromium engine. The web pages are rendered by Chromium engine off-screen and displayed in the lightweight Swing/JavaFX component. It's very [easy to use](https://jxbrowser.support.teamdev.com/support/solutions/articles/9000012864-quick-start-guide-for-swing-developers). It's free for Open-Source and Academic projects. – Vladimir Sep 12 '16 at 19:42
  • i thought, it is commercial. I mean how could you get the free license @Vladimir ? – gumuruh Jan 25 '17 at 02:33
  • In the evaluation form at https://www.teamdev.com/jxbrowser#evaluate, select Open-Source or Academic. You will see short explanation: The evaluation licence will not work after this time. If you are doing an open source project, you can request a permanent licence via the link provided in the email you will receive. So, once you request evaluation, you will get an email you can write to to request a free license for open-source project. – Vladimir Jan 25 '17 at 16:28

15 Answers15

37

Since JavaFX 2.0 you can use now webview

enter image description here

OscarRyz
  • 196,001
  • 113
  • 385
  • 569
  • 1
    A howto is here: http://stackoverflow.com/a/8413289/4857 – Ande Turner May 19 '14 at 15:25
  • An alternative JavaFX library is JxBrowser with BrowserView component: http://www.teamdev.com/jxbrowser – Vladimir Apr 17 '15 at 13:58
  • WebView has some performance issues, see http://stackoverflow.com/questions/10762979/performance-of-webview-in-javafx – Stefan Jan 18 '17 at 06:15
  • shitty thing ever possible. worst performance, javascript seldom works, unwanted behavior. Can never be used in any good project – Zahan Safallwa Aug 07 '17 at 14:42
  • Just tried out WebView (Jan 9, 2021), and it is now very performant! (on macOS) Very nice overall and I think I will be making GUIs via this method (also lets me embed nice javascript widgets) – Shebla Tsama Jan 09 '21 at 20:57
22

I believe JWebPane is going to be the official way to embed a browser into a java app. Its based on the open sourced engine - WebKit, which is used in Apples Safari and Googles Chrome browsers.See this blog for details.

Jimmy
  • 1,433
  • 2
  • 14
  • 19
  • 1
    JWebPane shows no signs of activity/life... However mozswing seems to work pretty well. I tried the JNLP download version and it the page renders well. Memory usage is a high, but support for web standards is good as it is based on the Mozilla browser. Available at http://confluence.concord.org/display/MZSW/Home – Thimmayya Feb 05 '10 at 00:40
  • 1
    As of april 2010, this is not possible. It seems JWebPane is vaporware :( – Kees Kist Apr 29 '10 at 16:37
  • 1
    April 2011, almost, still no sign, just like JMF too, for video mission is like mission impossible. Firefox 4 is launched yesterday. –  Mar 23 '11 at 18:14
  • 22
    **Update** JWebPane changed into WebView in JavaFX 2.0 ( the libraries series ) See: http://download.oracle.com/javafx/2.0/webview/jfxpub-webview.htm for a sample screenshot of it running see: http://www.javamexico.org/blogs/oscarryz/webview_en_javafx ( not written in Java though but in a experimental JVM language ) – OscarRyz Jun 14 '11 at 21:44
  • 3
    Is WebView in JavaFX truly standalone cross platform or does it depend on any platform specific native components? More importantly, how does it stack up to rendering pages? It is powered by WebKit but is this as close to having a real browser when it comes to rendering websites? – KJW May 07 '12 at 01:34
  • 1
    may 2014.. is it possible now? – Dinoop Nair May 06 '14 at 12:07
  • 1
    october 2015, guys? are you there? – javaguest Oct 19 '15 at 13:14
  • 1
    it is possible now. Altough i am having problem with the sites using jquerry . – e13420xx Nov 04 '15 at 12:27
9

You could use SWT for your GUI. Its Browser control allows you to embed IE, Mozilla or Safari (depending on the platform you're running in) with little pain.

alexmcchessers
  • 954
  • 1
  • 13
  • 16
  • The return values of browser.evaluate() are limited to a view types. The JavaFx WebEngine can handle all kinds of return types by wrapping the return value in JSObject. – Stefan Jan 18 '17 at 06:17
9

You may try this: https://jdic.dev.java.net/

alt text
(source: java.net)

Or this: http://lobobrowser.org/java-browser.jsp

alt text
(source: lobobrowser.org)

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
OscarRyz
  • 196,001
  • 113
  • 385
  • 569
  • Its very good to have something atleast. But its very slow and the graphics is very bad compared to Chrome or Firefox 4 –  Mar 23 '11 at 17:49
  • No update for Lobo for 2 years – Paul Verest Jun 07 '11 at 09:15
  • @OzhanDuz any details about JDIC issues? I like the approach, but haven't used it myself yet. – Patrick Linskey Aug 21 '12 at 06:36
  • Stay away from JDIC, its not multiplatform, i am not sure but development might be stopped or not active. Use DJ Native Swing, you will get regular updates, better api and more stable. –  Aug 21 '12 at 10:27
3

JxBrowser has not been mentionned yet. It embed either Mozilla Firefox (Gecko), Apple Safari (WebKit) or Internet Explorer. Programmer's Guide

h3xStream
  • 6,293
  • 2
  • 47
  • 57
  • Also [JExplorer](http://www.teamdev.com/jexplorer/) is a cheaper solution by TeamDev if you do not need a cross-platform solution. – xmedeko Sep 16 '13 at 13:25
  • 2
    Starting from 4.0 version JxBrowser integrates with Chromium engine. – Vladimir Dec 06 '13 at 11:02
  • I've been looking for a real answer to this question for years, and JxBrowser version 4 is really a game changer. It is exactly what you'd hope a swing browser component would be. – CarlG Apr 08 '14 at 22:19
  • 1
    Now [JxBrowser](https://www.teamdev.com/jxbrowser) allows embedding Google Chromium engine into Java Swing/JavaFX applications. It supports two rendering modes: lightweight (off-screen) and heavyweight (GPU-accelerated). It's free for Open-Source projects. – Vladimir Jul 18 '16 at 10:07
3

You could also try the JWebBrowser from DJ Native Swing: http://djproject.sourceforge.net/ns

3

By far the most robust embeddable browser I am familiar with is the one in SWT. In fact, it is so flexible that the JavaDoc hover you can see in Eclipse is actually a browser, and the JavaDoc view actually supports things like animation!

The only risk with using SWT is that there are different versions of the SWT library for different platforms. I'm not sure if there is a singl jar you could include to cover everyone.

Uri
  • 88,451
  • 51
  • 221
  • 321
3

Take a look at https://xhtmlrenderer.dev.java.net/

l_39217_l
  • 2,090
  • 1
  • 13
  • 15
2

I have successfully opened a browser from Java using SWT. You can find code examples of how to use SWT to open a Browser window. It's very easy to do.

Eddie
  • 53,828
  • 22
  • 125
  • 145
  • The return values of browser.evaluate() are limited to a view types. The JavaFx WebEngine can handle all kinds of return types by wrapping the return value in JSObject – Stefan Jan 18 '17 at 06:18
2

You can embed a browser in a Swing/AWT GUI using the JDIC API. I don't see any mention of OS X, so it may not be of use to you.

McDowell
  • 107,573
  • 31
  • 204
  • 267
1

You could try a JEditorPane, it doesn't interpret advanced HTML, nor Javascript, nor advanced CSS, but you can write that part yourself, called the EditorKit. That is the class/object that is consulted by the JEditorPane or how it has to display its content.

I know its possible, because I tried and failed (:P), but it could be outdated or deprecated by now, I don't know.

11684
  • 7,356
  • 12
  • 48
  • 71
1

If you need a pure Java solution then you can try JWebEngine. It render HTML 4 very good. You can use it in an applet, Java webstart and on any platform. The using is very simple.

Horcrux7
  • 23,758
  • 21
  • 98
  • 156
1

Maybe Chromium Embedded Framework is an option for you. Specific to Java there is

javacef for SWT: https://github.com/wjywbs/javacef

java-cef for AWT: https://bitbucket.org/chromiumembedded/java-cef

Stefan
  • 10,010
  • 7
  • 61
  • 117
1

You can try Webrenderer or Ice Browser

Bart
  • 10,873
  • 7
  • 29
  • 23
0

If you look at The Minecraft launcher (the old one), look through LoginForm or LauncherFrame, you may be able to find out that method. There is a tutorial by kippykip on youtube on how to decompile and edit it: here

Emil Carr
  • 61
  • 1
  • 3