I want to embed my SWT browser in swing jframe. I try sample, but it need to resize the window to load browser window. what can I do to repaint the canvas, with out resizing?
Asked
Active
Viewed 6,477 times
6
-
Why do you want to do this? What's the requirement? Why not use any of the Swing alternatives? – Baz Jul 16 '14 at 13:47
-
I want to load my html page in my java desktop application and execute my javascript code on it. I found a browser class, it is good but it is behind the jframe which call it, and also I cant do any thing in other open jframe while the browser window is open – user3813088 Jul 16 '14 at 13:52
-
So why not use any of the Swing alternatives? – Baz Jul 16 '14 at 13:53
-
which alternatives you recommend? – user3813088 Jul 16 '14 at 14:06
-
http://stackoverflow.com/questions/145863/best-java-swing-browser-component – Baz Jul 16 '14 at 14:09
1 Answers
8
Here is a working example on GIT showing how to embed SWT in a traditional Swing JPanel: https://gist.github.com/caprica/6890618 (Text version: here)
The trick is to create a java.awt.Canvas
linked to an SWT shell. This canvas can be added to any tradionnal Swing component. The SWT shell loop is managed by a separate thread.
Here is a screenshot on my Windows 7 box with Java 7:

Stephan
- 41,764
- 65
- 238
- 329
-
djbrowser i a better solution i think,it wrapps the swt stuff and code becomes readable and manageable. You don have to deal with SWT shells etc. – benchpresser Mar 11 '15 at 13:34
-
1
-
The example does work on Windows 7 with Java6, but the same problem occurs as the OP mentioned. You have to resize the frame before anything is visible – THelper May 19 '15 at 12:45