forked from webview/webview_java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwingExample.java
More file actions
47 lines (35 loc) · 1.32 KB
/
SwingExample.java
File metadata and controls
47 lines (35 loc) · 1.32 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
47
package dev.webview;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
public class SwingExample {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.setLayout(new BorderLayout());
// Using createAWT allows you to defer the creation of the webview until the
// canvas is fully renderable.
Component component = Webview.createAWT(true, (wv) -> {
// Calling `await echo(1,2,3)` will return `[1,2,3]`
wv.bind("echo", (arguments) -> {
return arguments;
});
wv.loadURL("https://google.com");
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
wv.close();
frame.dispose();
System.exit(0);
}
});
// Run the webview event loop, the webview is fully disposed when this returns.
wv.run();
});
frame.getContentPane().add(component, BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setVisible(true);
}
}