Last active
October 1, 2021 12:14
-
-
Save AlexGladkov/6572f1932319bad336c5eec352bf111e to your computer and use it in GitHub Desktop.
JFXPanel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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