-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathExample.java
More file actions
41 lines (28 loc) · 1.18 KB
/
Copy pathExample.java
File metadata and controls
41 lines (28 loc) · 1.18 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
package com.example.webview_java;
import dev.webview.webview_java.Webview;
public class Example {
public static void main(String[] args) {
Webview wv = new Webview(true); // Can optionally be created with an AWT component to be painted on.
// Calling `await echo(1,2,3)` will return `[1,2,3]`
wv.bind("echo", (arguments) -> {
return arguments;
});
// Calling `await echo(1,2,3)` will return `[1,2,3]`
wv.bind("setDarkAppearance", (arguments) -> {
wv.setDarkAppearance(arguments.contains("true")); // Use an actual Json parser. This is just a dirty example.
return null;
});
wv.setTitle("My Webview App");
wv.setSize(800, 600);
// load a URL
wv.loadURL("https://google.com");
/*
Or, load raw html from a file with:
wv.setHTML("<h1>This is a test!<h1>");
String htmlContent = loadContentFromFile("index.html");
wv.setHTML(htmlContent);
*/
wv.run(); // Run the webview event loop, the webview is fully disposed when this returns.
wv.close(); // Free any resources allocated.
}
}