Skip to content

Instantly share code, notes, and snippets.

@AlexGladkov
Last active October 1, 2021 12:14
Show Gist options
  • Save AlexGladkov/6572f1932319bad336c5eec352bf111e to your computer and use it in GitHub Desktop.
Save AlexGladkov/6572f1932319bad336c5eec352bf111e to your computer and use it in GitHub Desktop.
JFXPanel
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.openjfx.javafxplugin") version "0.0.10"
}
repositories {
mavenCentral()
}
val javafxModules = arrayOf("controls", "swing", "fxml", "graphics", "web")
javafx {
modules = javafxModules.map { "javafx.$it" }
}
kotlin {
jvm {
withJava()
}
sourceSets {
named("commonMain")
named("jvmMain") {
dependencies {
implementation(compose.desktop.currentOs)
implementation(project(":common:webview-desktop"))
}
}
named("jvmTest") {
dependencies {
implementation("junit:junit:4.12")
}
}
}
}
public class DesktopWebView {
public static JFrame renderWebView(String url) {
JFrame frame = new JFrame();
final JFXPanel fxPanel = new JFXPanel();
frame.add(fxPanel);
frame.setSize(300, 200);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Platform.runLater(() -> {
System.out.println("Start loading web");
WebView view = new WebView();
fxPanel.setScene(new Scene(view));
view.getEngine().load(url);
});
return frame;
}
}
fun main() = SwingUtilities.invokeLater {
val jfxFrame = DesktopWebView.renderWebView(provideLoginUrl())
jfxFrame.defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE
jfxFrame.title = "Test webview"
jfxFrame.setSize(800, 600)
jfxFrame.isVisible = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment