Tags: awt, browser, embedding, html, java, jdic, pde, processing.org
Multiple JDIC browsers integrated into Processing sketch
A while back I posted a simple hack to open a web browser from Processing by using JDesktop Integration Components (JDIC). A recent discussion on the Processing forums asked about how to use it to open multiple browsers inside the actual Processing sketch window.
My original hack used an instance of org.jdesktop.jdic.browser.WebBrowser integrated into a java.awt.Panel instance and laid out in a java.awt.Frame. That meant that the browser would open in an external window. The discussion on the Processing forum asked specifically about opening multiple browsers in the main sketch window, so I made the following quick hack.
I’m posting the actual code below, but to run the example you should download the following ZIP file: JDIC_multiple.zip. It includes the JDIC binaries required to run it on Windows.
// JDIC_multiple.pde
// Marius Watz - http://workshop.evolutionzone.com
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.URL;
import java.net.MalformedURLException;
import org.jdesktop.jdic.browser.*;
aBrowser browser[];
long last;
void setup() {
size(800,600);
frame.setLayout(new GridLayout(2,2));
browser=new aBrowser[4];
for(int i=0; i<4; i++) {
browser[i]=new aBrowser();
browser[i].initPanel(400,300);
if(i==0) browser[i].setURL("http://www.google.com/");
if(i==1) browser[i].setURL("http://processing.org/");
if(i==2) browser[i].setURL("http://ffffound.com/");
if(i==3) browser[i].setURL("http://sojamo.tumblr.com/");
frame.add(browser[i].panel);
}
}
void draw() {
}
public class aBrowser {
Panel panel;
WebBrowser webBrowser;
public aBrowser() {
// Set engine to IE
BrowserEngineManager mng=BrowserEngineManager.instance();
mng.setActiveEngine(BrowserEngineManager.IE);
webBrowser = new WebBrowser();
}
public void initPanel(int w,int h) {
panel = new Panel();
panel.setLayout(new BorderLayout());
panel.setSize(w,h);
webBrowser.setSize(w, h);
panel.add(webBrowser, BorderLayout.CENTER);
}
public void setContent(String htmlContent) {
webBrowser.setContent(htmlContent);
}
public void setURL(String url) {
try {
webBrowser.setURL(new URL(url));
webBrowser.setDebug(false);
}
catch (MalformedURLException e) {
System.out.println(e.getMessage());
return;
}
}
}





i have one problem , i want to embed wed page in awt but dont want use any swing component.
because my device does not support swing or higher version of java.
if u have any idea then plz let me know…
Hi friend,
I have a problem to be solved. How i could get input values from a loaded html form at run time. I have used the dom but it retreives old value. Can we do it using jdic both for ie and mozilla. At present i am using webrenderer http://www.webrenderer.com/products/desktop/product/.
But it is commercial. I want to develop it myself.
plz help
manu
hai manu ….
i am also in need of embedding a webbrowser in to my swing/ awt application.
I am not very experienced in this stuff … Just googled for my requirements.
I came across webrenderer, jdic, mozswing and some others as well .. webrendere as u said is too expensive ..
jdic is good .. But though the developers claim support for mozilla ….
firefox canot be used with jdic . JDIC supports only .
INone blog a blogger said he was able to run mozilla 1.7. …some older verison with jdic ..
in jdic i was not able to retrieve the values using javacode ..
but it supports javascript …
and with a ixture of java + javascript i was able to do it ….
Mozswing just supports firefox ….
but it can retrieve the run time values wihtout any javascript code …
Thinking this information might help u in some way ,,,
martin
JDIC supports only IE …