Over a million developers have joined DZone.

Web Browser in Your Java Swing Application

· Java Zone

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

Do you develop a desktop Java Swing application and need a component that could display all modern web pages including Flash and Ajax? In this case JxBrowser library is what you need.

JxBrowser gives you a possibility to embed a rich web browser component into your Swing-based Java desktop applications. So web documents, inside your application will look exactly like in a web browser that they are designed for. JxBrowser supports integration with Internet Explorer and Mozilla (corresponding Firefox 3) under Windows, Apple Safari and Mozilla under Mac OS X, and Mozilla under Linux platforms.

This library provides a lot of features, but let's see how easy you can embed a Browser component into your Java Swing application and navigate on Google web page:

import com.teamdev.jxbrowser.Browser;import com.teamdev.jxbrowser.BrowserFactory;import com.teamdev.jxbrowser.BrowserType;import javax.swing.*;import java.awt.*;public class BrowserSample {    public static void main(String[] args) {        Browser browser = BrowserFactory.createBrowser(BrowserType.Mozilla);         JFrame frame = new JFrame();        frame.add(browser.getComponent(), BorderLayout.CENTER);        frame.setSize(700, 500);        frame.setLocationRelativeTo(null);        frame.setVisible(true);         browser.navigate("http://www.google.com");    }}

That's it!

If you configured your Java project with JxBrowser library as well, then you should see the following output when you run this example.

In the next article I will show you how to listen for the browser events such as start and completion of navigation, track page downloading progress and more.

Any comments or suggestions as for the other articles will be highly appreciated.

Links:

About library: http://www.teamdev.com/jxbrowser
Samples: https://sites.google.com/a/teamdev.com/jxbrowser-support/demo-and-samples

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:
java

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}