-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaFxBrowser.java
More file actions
46 lines (35 loc) · 1.16 KB
/
JavaFxBrowser.java
File metadata and controls
46 lines (35 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javax.swing.*;
import java.awt.*;
public class JavaFxBrowser implements Runnable {
private WebEngine webEngine;
public static void main(String[] args) {
SwingUtilities.invokeLater(new JavaFxBrowser());
}
public void loadURL(final String url) {
Platform.runLater(() -> {
webEngine.load(url);
});
}
@Override
public void run() {
// setup UI
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setPreferredSize(new Dimension(1024, 600));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JFXPanel jfxPanel = new JFXPanel();
frame.getContentPane().add(jfxPanel);
frame.pack();
Platform.runLater(() -> {
WebView view = new WebView();
webEngine = view.getEngine();
jfxPanel.setScene(new Scene(view));
});
loadURL("http://www.google.com");
}
}