how to embed SWT browser in swing jframe
Asked Answered
T

1

6

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?

Teazel answered 16/7, 2014 at 13:46 Comment(5)
Why do you want to do this? What's the requirement? Why not use any of the Swing alternatives?Shantae
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 openTeazel
So why not use any of the Swing alternatives?Shantae
which alternatives you recommend?Teazel
#146363Shantae
H
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: enter image description here

Hummel answered 3/1, 2015 at 12:24 Comment(3)
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.Umeko
@Umeko Can you post some sample code in a response?Hummel
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 visibleVassalage

© 2022 - 2024 — McMap. All rights reserved.