Java SWT web browser embedded in swing on the Raspberry PI

As I was working on a Rapsberry PI project I had a requirment to run a web browser inside a Java Swing project. I worked 3 month to get a browser on the Raspberry PI, I have tried various options including JavaFX webview, DJNativeSwing webBrowser, JCEF(embedded chromium) which all didnt work. finally after some time I found the answer: a native SWT web browser, and it worked with no errors, no exceptions, no missing DLLs.

here is the basic solution steps:
1. install requiered libraries:
sudo apt-get install libswt-gtk-3-jni libswt-gtk-3-java libswt-webkit-gtk-3-jni libwebkitgtk-1.0-0
2. create a simple java swt browser app as folows:

// Import SWT. import org.eclipse.swt.SWT; // Import UI components. import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; // Import the browser component. import org.eclipse.swt.browser.Browser; // Create a class for instantiating the encapsulating Java application. public final class Main { // Holds the Java window and its properties. private Display display; private Shell shell; private FillLayout layout; // Holds the browser widget. private Browser browser; // Application title and settings. private static final String title = "Sample JJR Application"; private static final int height = 800; private static final int width = 600; // RIA location. private static final String URL = "http://localhost/"; // Class constructor used for creating the basic Java UI, including the browser. public Main() { // Prepare window. this.display = new Display(); = new Shell(this.display);, Main.height);; this.layout = new FillLayout();; // Create browser. this.browser = new Browser(,SWT.NONE); this.browser.setUrl(Main.URL); // Add custom JavaScript function. new HelloWorld( this.browser, // Browser widget. "Hello" // JS function name. ); // Display window.; while (! { if (!this.display.readAndDispatch()) this.display.sleep(); } this.display.dispose(); } // Application entry point. public static void main(String[] args) { // Start the application. new Main(); } }

3. include the /usr/share/java/swt-gtk-3.8.jar in the class path or just import the jar in to your project, and export the project to a runnable jar.

to embed the browser on swing use the code above ( taken from )

import java.awt.BorderLayout; import java.awt.Canvas; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; import org.eclipse.swt.SWT; import org.eclipse.swt.awt.SWT_AWT; import org.eclipse.swt.browser.Browser; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; /** * A simple canvas that encapsulates a SWT Browser instance. * Add it to a AWT or Swing container and call "connect()" after * the container has been made visible. */ public class BrowserCanvas extends Canvas { private Thread swtThread; private Browser swtBrowser; /** * Connect this canvas to a SWT shell with a Browser component * and starts a background thread to handle SWT events. This method * waits until the browser component is ready. */ public void connect() { if (this.swtThread == null) { final Canvas canvas = this; this.swtThread = new Thread() { @Override public void run() { try { Display display = new Display(); Shell shell = SWT_AWT.new_Shell(display, canvas); shell.setLayout(new FillLayout()); synchronized (this) { swtBrowser = new Browser(shell, SWT.NONE); this.notifyAll(); }; while (!isInterrupted() && !shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } shell.dispose(); display.dispose(); } catch (Exception e) { interrupt(); } } }; this.swtThread.start(); } // Wait for the Browser instance to become ready synchronized (this.swtThread) { while (this.swtBrowser == null) { try { this.swtThread.wait(100); } catch (InterruptedException e) { this.swtBrowser = null; this.swtThread = null; break; } } } } /** * Returns the Browser instance. Will return "null" * before "connect()" or after "disconnect()" has * been called. */ public Browser getBrowser() { return this.swtBrowser; } /** * Stops the swt background thread. */ public void disconnect() { if (swtThread != null) { swtBrowser = null; swtThread.interrupt(); swtThread = null; } } /** * Ensures that the SWT background thread * is stopped if this canvas is removed from * it's parent component (e.g. because the * frame has been disposed). */ @Override public void removeNotify() { super.removeNotify(); disconnect(); } /** * Opens a new JFrame with BrowserCanvas in it */ public static void main(String[] args) { // Required for Linux systems System.setProperty("sun.awt.xembedserver", "true"); // Create container canvas. Note that the browser // widget will not be created, yet. final BrowserCanvas browserCanvas = new BrowserCanvas(); browserCanvas.setPreferredSize(new Dimension(800, 600)); JPanel panel = new JPanel(new BorderLayout()); panel.add(browserCanvas, BorderLayout.CENTER); // Add container to Frame JFrame frame = new JFrame("My SWT Browser"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setContentPane(panel); frame.pack(); // This is VERY important: Make the frame visible BEFORE // connecting the SWT Shell and starting the event loop! frame.setVisible(true); browserCanvas.connect(); // Now we can open a webpage, but remember that we have // to use the SWT thread for this. browserCanvas.getBrowser().getDisplay().asyncExec(new Runnable() { @Override public void run() { browserCanvas.getBrowser().setUrl(""); Shell shell = browserCanvas.getBrowser().getShell(); shell.pack(); } }); } }

in this solution we use swing Jframe and a JPanel with a border layout. this layout works, but card layout does not work with this browser. you have to create the browser canvas and add it to the frame and set the frame visible before connecting to the swt browser, or else it will not work.

this solution works on the raspberry, but there are some problems. if you want to close the browser, and then display it again you simply call disconnect and connect, it will work on windows. on the raspberry when you try to call connect after disconnect it will crash the JVM. so you need to modify the code to keep the SWT Browser,Shell,Display not disposing, and do not disconnect the canvas from the JFrame. if you disconnect the canvas from the JFrame you cannot re connect the canvas. you need to dispose the SWT elements after the JFrame windowClosed event has fired on a WindowListener. its not a pretty solution but its the only solution I have found.

please feel free to comment about this, and ask questions.



G [url=]eitcha lele movies[/url]
H [url=]zarys zdarzen do fury[/url]
Z [url=]dreambox channel icons s[/url]
M [url=]ritam nereda albumin itunes[/url]
M [url=]symbol of rupees movies[/url]
Z [url=]einstein and eddington[/url]
T [url=]corba protocol wireshark[/url]
S [url=]pakistani tv channels live streaming software[/url]
B [url=]discografia roberto carlos yahoo[/url]
R [url=]faze bang like a drum[/url]
T [url=]cvbot biohazard music[/url]
G [url=]impresora hp j110a[/url]
S [url=]cine n are ibovnica movies[/url]
Z [url=]sta ce mi salvare vera ivkovic youtube[/url]
C [url=]musafir movie hot video[/url]
Q [url=]mozilla firefox latest version for windows 7 home premium[/url]
B [url=]gucci mane ft wiz khalifa 2 timez mixtape s[/url]
A [url=https://fam


R [url=]shoutcast winamp baixaki s[/url]
G [url=]he antennas[/url]
V [url=]debbo v3 5 baixaki google[/url]
U [url=]mx video player armv6 codec 1.5 pack apk[/url]
K [url=]nokia e5 puzzle bobble game[/url]
S [url=]eylo seni seviyorum firefox[/url]
D [url=]disco deewane songs 2012[/url]
E [url=]eu is seful strazilor zippy[/url]
C [url=]busou renkin sub indo 480playnow[/url]
U [url=]xavier quijas yxayotl music[/url]
Y [url=]wind river linux 4.0[/url]
B [url=]nds 3 temporada dublado[/url]
M [url=]mca 1.6.4[/url]
V [url=]film o f1 2013[/url]
R [url=]elias silva o mysteriously[/url]
O [url=]big bang extraordinary 20s[/url]
Y [url=]bangla buddha dhamma book[/url]
E [url=]maria kollmer bodenmais germany[/url]
I [url=


P [url=]claudia asu si ticy zalele movies[/url]
M [url=]avunanna kadanna telugu movie songs cinemelody[/url]
Q [url=]catholic bible[/url]
D [url=]asiafone af7997 hello kitty firmware[/url]
E [url=]field mob smilin games[/url]
X [url=]goyang yks pokok joget workflow[/url]
Y [url=]tosko una noche mas mp3[/url]
D [url=]farxiga kabayare zamzam[/url]
M [url=]parcheggi strani video[/url]
M [url=]code lyoko ifscl 2.6.2 youtube[/url]
I [url=]idm full crack 6.05 mien phi[/url]
L [url=]mugen sprites maker[/url]
W [url=]hans derer 7usaini7[/url]
Q [url=]lr point blank br v6 movies[/url]
T [url=]kuro no tenshi google[/url]
H [url=]pink floyd the final cut blogspot[/url]
M [url=]christophe mae mon paradis album s[/url]
S [url=


G [url=]rar iphone[/url]
C [url=]staad pro v8i for windows 8[/url]
M [url=]festival rock indonesia ke-68-av keyless entry[/url]
U [url=]volker pispers podcast[/url]
D [url=]tubemate para pc windows 7 baixaki[/url]
Q [url=]makai ouji devils and realist anime site[/url]
L [url=]koizora filme legendado definition[/url]
F [url=]nagin tune colors[/url]
R [url=]cw warface[/url]
B [url=]dirtiest hockey hits every tree[/url]
A [url=]lagu rabbani hanzalah allah[/url]
X [url=]master manzoor new album 2012[/url]
M [url=]incognito rabbit killer[/url]
L [url=]shoemaster[/url]
I [url=]bridelia ferruginea pdf[/url]
D [url=]opus diaboli watain youtube[/url]
M [url=]rihanna love songs mp3[/url]
L [url=]force delta game[/url]
Z [url=


R [url=]it solutions 4 you pdf maker[/url]
D [url=]st lucia we got it wrong mp3[/url]
F [url=]jazzpunk 2[/url]
R [url=]atharva veda in telugu[/url]
G [url=]the song of boss[/url]
C [url=]all about the money troy ave mp3[/url]
M [url=]stronghold legends full game torent[/url]
I [url=]what can i use to music straight to my iphone[/url]
A [url=]indian bodybuilding show[/url]
H [url=]glaube an dich und werde reich pdf[/url]
G [url=]om zagita lumpuhkan ingatanku[/url]
D [url=]hp deskjet 840c service manual[/url]
F [url=]lite iphone film accessories[/url]
B [url=]manolo lezcano exitos rar[/url]
D [url=]converter mswrd632 software[/url]
E [url=]nota lokos la mas linda del salon karaoke s[/url]
G [url=]sswalloww instagram[/url]
B [url=


M [url=]changampuzha kavitha mp3[/url]
K [url=]sirshendu mukhopadhyay ebook[/url]
U [url=]samsung ml-1641 driver[/url]
W [url=]hachibi vs kisame vs guy[/url]
H [url=]sniper ghost warrior 2 wallpaper hd[/url]
V [url=]imtoo converter crack[/url]
E [url=]sis 315 ubuntu[/url]
K [url=]mah o mahi games[/url]
A [url=]11 eyes anime op[/url]
V [url=]talib kweli kendrick lamar push thru music[/url]
X [url=]pc puzzle games s[/url]
T [url=]komik chibi maruko chan characters[/url]
R [url=]marjan kandi shahriyar shahbazi music[/url]
Q [url=]bassically tei shi[/url]
X [url=]songbooks piano[/url]
X [url=]mattara send the message[/url]
E [url=]gianni celeste figlio e carcerato music[/url]
O [url=]guilty crown episode 1-225[/url]
N [ur


G [url=]rome total history[/url]
A [url=]xemx instrumental s[/url]
I [url=]ahange eshghe bi gonah[/url]
T [url=]darude sandstorm mp3juices[/url]
O [url=]lagu bunga ateha[/url]
B [url=]disk order bandcamp er[/url]
K [url=]whitehill technologies inc moncton hotels[/url]
M [url=]mp3 dazzling tears by december[/url]
P [url=]nas4 32 bit[/url]
H [url=]fluxogram software s[/url]
N [url=]soprano puisquil faut vivre album mp3[/url]
R [url=]film planes 2013[/url]
G [url=]faces of death 3gp[/url]
E [url=]tuze rup chitti raho skype[/url]
N [url=]fesco job interview questions and answers[/url]
P [url=]cabin fever 2 iphone 4[/url]
E [url=]marjan farsad afsaneh mp3[/url]
X [url=]quakespasm youtube[/url]
D [url=]omnipag


P [url=]interview mastery[/url]
D [url=]windows xp2 software developers[/url]
G [url=]document 1 microsoft word[/url]
C [url=]descomprimir archivos 001 hj split mac s[/url]
M [url=]nas vs shared hd er[/url]
U [url=]caca manalu[/url]
X [url=]harlem globetrotters video tricks[/url]
N [url=]zmieniaj mnie gdy zechcesz[/url]
L [url=]ssc cgl exam preparation book[/url]
U [url=]kaisi yeh yaariaan episode 67 google[/url]
X [url=]frosty morning with cardinals[/url]
D [url=]smf hahaha zippyshare[/url]
B [url=]rocketalk for nokia c6 hard[/url]
Q [url=]tantra bot system 2.00[/url]
C [url=]manke lehmber hussainpuri new album[/url]
F [url=]gcdocs content server s[/url]
E [url=]fadil berisha instagram[/url]
O [url=]progressive house melodics 3[


P [url=]tosko una noche mas mp3[/url]
K [url=]kurt travis wha happen games[/url]
S [url=]k lite codec pack softonic skype[/url]
W [url=]argatu lie ciocarlie youtube[/url]
X [url=]torntv er que es curcuma[/url]
E [url=]sahasam wasaga sagapo songs doregama s/o[/url]
L [url=]4d zeleny dym ektor movies[/url]
Q [url=]antivirus gratis italiano per windows 7 2012[/url]
P [url=]exist ikhlasnya hati[/url]
V [url=]dvd lab pro cracked steam[/url]
O [url=]x-plane 11[/url]
A [url=]wanted film songs mp3[/url]
L [url=]tollywood new movies 2012[/url]
R [url=]deepcentral speed of sound hotfiles[/url]
H [url=]hizteria mp3[/url]
L [url=]faceit fpl rankings na csgo ranking[/url]
F [url=]new one joe moses music[/url]
T [url=]nero 9 full


N [url=]yle areena ulkomailla vpn[/url]
Y [url=]games for tablet android 4.0[/url]
R [url=]void stiles best moments on instagram[/url]
M [url=]innocent blood 1992 greek subs[/url]
K [url=]magnetic field solenoid pdf[/url]
F [url=]theme song wwe royal rumble[/url]
G [url=]saw 1 myegy s[/url]
L [url=]canon pixma mg3120 printer software[/url]
G [url=]chrome osx[/url]
V [url=]ikspi video movie trailer[/url]
E [url=]lenovo u510 review pcmag s[/url]
B [url=]lagu endah n rhesa waiting[/url]
X [url=]tekkit empty factory[/url]
U [url=]bitburger werbung youtube er[/url]
I [url=]c5 03 wallpaper mobile9 s[/url]
Y [url=]transport heavy typeface s[/url]
T [url=]sintetizador online de voz kid[/url]
F [url=]modern warfare 3 multi

הוסף תגובה

שם משתמש: