Last active
April 11, 2021 14:15
-
-
Save davidjgraph/b89d98611362ee4588af to your computer and use it in GitHub Desktop.
draw.io wraped in a Java WebView
This file contains hidden or 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 javafx.application.Application; | |
import javafx.geometry.HPos; | |
import javafx.geometry.VPos; | |
import javafx.scene.Node; | |
import javafx.scene.Scene; | |
import javafx.scene.layout.HBox; | |
import javafx.scene.layout.Priority; | |
import javafx.scene.layout.Region; | |
import javafx.scene.paint.Color; | |
import javafx.scene.web.WebEngine; | |
import javafx.scene.web.WebView; | |
import javafx.stage.Stage; | |
public class WebViewSample extends Application { | |
private Scene scene; | |
@Override public void start(Stage stage) { | |
// create the scene | |
stage.setTitle("Web View"); | |
scene = new Scene(new Browser(),900,600, Color.web("#666970")); | |
stage.setScene(scene); | |
stage.show(); | |
} | |
public static void main(String[] args){ | |
launch(args); | |
} | |
} | |
class Browser extends Region { | |
final WebView browser = new WebView(); | |
final WebEngine webEngine = browser.getEngine(); | |
public Browser() { | |
//apply the styles | |
getStyleClass().add("browser"); | |
// load the web page | |
webEngine.load("https://www.draw.io?demo=1"); | |
//add the web view to the scene | |
getChildren().add(browser); | |
} | |
private Node createSpacer() { | |
Region spacer = new Region(); | |
HBox.setHgrow(spacer, Priority.ALWAYS); | |
return spacer; | |
} | |
@Override protected void layoutChildren() { | |
double w = getWidth(); | |
double h = getHeight(); | |
layoutInArea(browser,0,0,w,h,0, HPos.CENTER, VPos.CENTER); | |
} | |
@Override protected double computePrefWidth(double height) { | |
return 900; | |
} | |
@Override protected double computePrefHeight(double width) { | |
return 600; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment