Best Java/Swing Browser Component

Best Java/Swing browser component?

i belive this could help:

http://djproject.sourceforge.net/ns/index.html

Best component in awt/swings to display the webpage and access it

Jbrowser is used xullrunner form mozilla project, so jbrowser is wrapper for firefox browser.

For my issue i used NativeSwing library , it is best component i feel.with this i implemented integrating webpage which is non html page in to Swing application.

Web Browser Control in Java?

https://docs.oracle.com/javafx/2/webview/jfxpub-webview.htm
I think this is the widget you're looking for. From the official JavaFX website.

Best way to integrate Browser into Java application

Think about using Eclipse as 'Rich Client'. You'll have no trouble using the internal browser that comes with it.

See here.

Embed Firefox browser in Java Swing

Absolutely I have done it before please check out the Mozilla Embedding for Java

Here is some sample code

import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.File;

import javax.swing.*;

import org.mozilla.xpcom.*;
import org.mozilla.interfaces.*;

/*
Websites ref
http://groups.google.com/group/mozilla.dev.tech.java/browse_thread/thread/898ba6751d0c57f7
http://skrul.com/blog/code/
http://wirestorm.net/blog/?cat=9

*/

public class BrowserTest implements nsIWebProgressListener,nsIWeakReference, nsIInterfaceRequestor, nsIWebBrowserChrome, nsISHistoryListener{
static {
try {
System.loadLibrary("NativeWindow");
} catch (UnsatisfiedLinkError e) {
System.err.println("can't find your library");
}
}
private static final String frameTitle="GRE Embedded";
public static void main(String[] args) {
BrowserConroller controler=new BrowserConroller();
controler.run();
new BrowserTest().start();
}

public void start(){

JFrame f = new JFrame( frameTitle );
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(400, 150);
Container content = f.getContentPane();
content.setBackground(Color.white);
content.setLayout(new FlowLayout());
content.add(new JLabel("Initializing ... "));
f.setVisible(true);

File grePath = null;
LocationProvider locProvider;
Mozilla mozilla = Mozilla.getInstance();

GREVersionRange[] range = new GREVersionRange[1];
range[0] = new GREVersionRange("1.8.0", true, "1.9", false);

try {
grePath = Mozilla.getGREPathWithProperties(range, null);
mozilla.initialize(grePath);
locProvider = new LocationProvider(grePath);
mozilla.initEmbedding(grePath, grePath, locProvider);
}

catch (FileNotFoundException e) {
System.out.println("Error: FileNotFoundException");
}
catch (XPCOMException e) {
System.out.println("Error: XPCOMException");
}

//---------- END GRE INITIALIZATION------------

nsIServiceManager serviceManager = mozilla.getServiceManager();

nsIAppStartup appStartup = (nsIAppStartup)serviceManager.getServiceByContractID("@mozilla.org/toolkit/app-startup;1", nsIAppStartup.NS_IAPPSTARTUP_IID);
nsIWindowCreator windowCreator = (nsIWindowCreator)appStartup.queryInterface(nsIWindowCreator.NS_IWINDOWCREATOR_IID);

nsIWindowWatcher windowWatcher =(nsIWindowWatcher)serviceManager.getServiceByContractID("@mozilla.org/embedcomp/window-watcher;1",nsIWindowWatcher.NS_IWINDOWWATCHER_IID);

windowWatcher.setWindowCreator(windowCreator);

nsIDOMWindow win = windowWatcher.openWindow(null, "http://google.com", "MAIN_WIN","chrome,resizable,centerscreen", null);
windowWatcher.setActiveWindow( win );

nsIComponentManager componentManager = mozilla.getComponentManager();
String NS_IWEBBROWSER_CID = "F1EAC761-87E9-11d3-AF80-00A024FFC08C"; //$NON-NLS-1$
nsIWebBrowser webBrowser = (nsIWebBrowser) componentManager.createInstance(NS_IWEBBROWSER_CID, null, nsIWebBrowser.NS_IWEBBROWSER_IID);
webBrowser.setContainerWindow(this);
webBrowser.addWebBrowserListener(this, nsIWebProgressListener.NS_IWEBPROGRESSLISTENER_IID);

// nsIWebNavigation webNavigation=(nsIWebNavigation)webBrowser.queryInterface(nsIWebNavigation.NS_IWEBNAVIGATION_IID);
// webNavigation.loadURI("http://www.zdnet.com", nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
//

nsIBaseWindow baseWindow = (nsIBaseWindow) webBrowser.queryInterface(nsIBaseWindow.NS_IBASEWINDOW_IID);
long handle=FindWindow.getHWND( frameTitle );

baseWindow.initWindow(handle, 0, 0, 0,350,350);
baseWindow.create();
baseWindow.setVisibility(true);

//
// nsIDOMWindow domWin=webBrowser.getContentDOMWindow();
// nsIDOMEventTarget domEventTarget= (nsIDOMEventTarget)domWin.queryInterface(nsIDOMEventTarget.NS_IDOMEVENTTARGET_IID);
// domEventTarget.addEventListener("click", new EventListener(), false);
//
//Hide JFrame after it have been initialized
f.setVisible(true);
//
// nsIWebNavigation webNavigation=(nsIWebNavigation)webBrowser.queryInterface(nsIWebNavigation.NS_IWEBNAVIGATION_IID);
// webNavigation.loadURI("http://www.zdnet.com", nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
//
appStartup.run();
System.out.println("try termEmbedding");
try {
System.out.println("mozilla.termEmbedding(); START");
mozilla.termEmbedding();
System.out.println("mozilla.termEmbedding(); FINISHED");
}
catch (XPCOMException e) {
System.out.println("Fehler: XPCOMException");
}
System.out.println("finished termEmbedding");
System.out.println("All done");
}

public void onLocationChange(nsIWebProgress webProgress, nsIRequest request, nsIURI location) {
c("onLocationChange");

}

public void onProgressChange(nsIWebProgress webProgress, nsIRequest request, int curSelfProgress, int maxSelfProgress, int curTotalProgress, int maxTotalProgress) {
c("onProgressChange");

}

public void onSecurityChange(nsIWebProgress webProgress, nsIRequest request, long state) {
c("onSecurityChange");

}

public void onStateChange(nsIWebProgress webProgress, nsIRequest request, long stateFlags, long status) {
c("onStateChange");

}

public void onStatusChange(nsIWebProgress webProgress, nsIRequest request, long status, String message) {
c("onStatusChange");

}

public nsISupports queryInterface(String uuid) {
c("queryInterface");
return null;
}

public nsISupports queryReferent(String uuid) {
c("queryReferent");
return null;
}

public nsISupports getInterface(String uuid) {
c("getInterface");
return null;
}
private void c(Object o){
System.out.println(o);
}

public void destroyBrowserWindow() {
c("destroyBrowserWindow");

}

public void exitModalEventLoop(long status) {
c("exitModalEventLoop");

}

public long getChromeFlags() {
c("getChromeFlags");
return 0;
}

public nsIWebBrowser getWebBrowser() {
c("getWebBrowser");
return null;
}

public boolean isWindowModal() {
c("isWindowModal");
return false;
}

public void setChromeFlags(long chromeFlags) {
c("setChromeFlags");

}

public void setStatus(long statusType, String status) {
c("setStatus");

}

public void setWebBrowser(nsIWebBrowser webBrowser) {
c("setWebBrowser");
}

public void showAsModal() {
c("showAsModal");

}

public void sizeBrowserTo(int acx, int acy) {
c("sizeBrowserTo");

}

public boolean onHistoryGoBack(nsIURI backURI) {
c("onHistoryGoBack");
return false;
}

public boolean onHistoryGoForward(nsIURI forwardURI) {
c("onHistoryGoForward");
return false;
}

public boolean onHistoryGotoIndex(int index, nsIURI gotoURI) {
c(" onHistoryGotoIndex");
return false;
}

public void onHistoryNewEntry(nsIURI newURI) {
c(" onHistoryNewEntry");
}

public boolean onHistoryPurge(int numEntries) {
c(" onHistoryPurge");
return false;
}

public boolean onHistoryReload(nsIURI reloadURI, long reloadFlags) {
c(" onHistoryReload");
return false;
}

} //public class JavaXPCOM_test1[/code]

Adding a Web Browser in a JFrame/JPanel/JComponent in Java

The obvious one that everyone is avoiding is JEditorPane which is right in swing. It's a pig and very limited but for certain types of HTML rendering it does ok.

I have used it for simpler jobs.

As mentioned in the other links, Lobo Browser is another option. The cobra stuff in that is pretty good and handles a lot more pages than JEditorPane. I found it does all of my medium jobs but has some frustratingly unextensible parts of its design. I use it for my help systems and some non-AJAX heavy web work.

For anything like google maps, and those sorts of heavy AJAX style web applications, you are pretty much stuck with DJ Native as another poster and the other question responses mention. Since it's shelling out to a real browser underneath the covers it will handle any web site. The only down side is that you lose a certain level of control over what it's doing since you have to make calls to it through Java script and get events back through a similar mechanism.

As an example no sane person would need, I've had applications that rendered swing controls (reports, etc.) right into the web page on the fly. In JEditorPane this was confounding but possible. In Cobra it's almost easy but a few private or final methods requiring work-arounds. In DJ Native, it would be impossible without generating the image ahead of time and making it available via URL (either local or remote).

So it all depends on your needs. For free, there is no perfect solution.

How to deploy Java Swing Application on Web Browser?

Old days

As commented by TrogDor, there were previously two ways to deploy a Swing app through the web:

  • Java Applet technology
    Your app would appear within a rectangle on the web page, within the browser.
  • Java Web Start technology
    Clicking a link on a web page would download a copy of your Swing app to the user’s local machine, where your app would then be launched locally using a locally-installed JVM. So your app runs separate from the web browser. This click-to-download-and-run process is defined by Java Network Launching Protocol (JNLP).

Both of these are being phased out.

➥ For details, see the white paper Java Client Roadmap Update published by Oracle, updated 2020-05-11.

Nowadays

The modern approach is to build a Swing and/or JavaFX app, then deploy by using a packaging tool to include a JVM. You end up with a complete self-contained self-launchable application.

This means you need multiple builds, one app for each platform your users may deploy on (macOS, Linux, BSD, Windows, and so on). While that is an additional burden to you, the flip-side is that you control exactly what version of Java is being used to run your app.

Because of the Java Platform Module System (JSR 376) in Java 9 and later, you can now strip down the bundled JVM and libraries to include only the parts actually used by your particular app.

The build tools for packaging your app have been rapidly evolving in recent years. So be sure to do your research to find the most robust and modern tooling.

Alternatives

You might consider any of these alternatives:

  • OpenWebStart
    A re-implementation of Java Web Start
  • GraalVM
    Ahead-of-time native-code compilation of your Java app
  • Vaadin Flow
    Using Java to build desktop-style apps delivered as web apps

OpenWebStart

You might be interested in a separate implementation of Java Web Start technology.

While Oracle is phasing out Java Web Start, there is an open-source implementation of JSR 56: Java Network Launching Protocol and API called OpenWebStart. See GitHub. This project is currently maintained by the company Karakun, based on the IcedTea-Web core functionality developed at Adoptium (née AdoptOpenJDK).

GraalVM

A cutting-edge alternative is to build an entirely native-code ahead-of-time compiled version of your app using GraalVM.

Vaadin Flow

An entirely different way to build a web app by using Java is the Vaadin Flow framework.

You specify your user-interface layouts with widgets in a manner quite similar to Swing, specifying an arrangement of widgets (buttons, fields, labels, etc.). You can do so using your choice of straight Java code, an XML-based description language, or a visual design tool.

At run-time, Vaadin automatically automatically generates the HTML, CSS, and JavaScript necessary to render your app remotely on the client user’s machine within a web browser. So, you have pure Java on the server-side, and no Java on the client-side, just Web standards technologies built into all modern browsers.

More info

All of this has been covered many times already on Stack Overflow. So search to learn more.

For tips on obtaining a JVM to bundle with your app, see How to get java 11 run-time environment working since there is no more jre 11 for download?.

Webkit browser in a Java app

There is one in development by Swing Team:
http://weblogs.java.net/blog/ixmal/archive/2008/05/introducing_jwe.html



Related Topics



Leave a reply



Submit