Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 541227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:19:20+00:00 2026-05-13T10:19:20+00:00

I am wondering if it is possible to embed Firefox browser as a component

  • 0

I am wondering if it is possible to embed Firefox browser as a component in a Java Swing based application.

I have done a bit of research from the Internet, but I could not find an answer. Some people suggest to use other browser component available in Java. I do not think that is preferable, as the rendering engine would be different to Firefox.

Any idea? Many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:19:20+00:00Added an answer on May 13, 2026 at 10:19 am

    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]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering how I could embed a browser like view in a Java
Is it possible to easily embed ActiveX controls in Java application? Is it worth
Just wondering is it possible to build CLI app that can be run from
I am wondering if its possible to have a an (||)or or (&&)and operator
I have not worked so much with files: I am wondering about possible issues
I am wondering if it is possible to embed a YouTube video on a
I have written an HTML Application (hta file) and am wondering if there is
I was wondering...is it possible to use a value from an array which is
Wondering if its possible to communication from javascript to flash without the use of
just wondering if its possible to have a hidden parent and a visible child

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.