Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Web Browser in Your Java Swing Application

DZone's Guide to

Web Browser in Your Java Swing Application

· Java Zone
Free Resource

Learn how to troubleshoot and diagnose some of the most common performance issues in Java today. Brought to you in partnership with AppDynamics.

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

Understand the needs and benefits around implementing the right monitoring solution for a growing containerized market. Brought to you in partnership with AppDynamics.

Topics:
java

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}