本文整理汇总了Java中javafx.scene.web.WebEngine类的典型用法代码示例。如果您正苦于以下问题:Java WebEngine类的具体用法?Java WebEngine怎么用?Java WebEngine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebEngine类属于javafx.scene.web包,在下文中一共展示了WebEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showAndWait
import javafx.scene.web.WebEngine; //导入依赖的package包/类
public static void showAndWait(String url,
Predicate<WebEngine> loginSuccessTest,
Consumer<WebEngine> handler) {
try {
FXMLLoader loader = new FXMLLoader(LoginController.class.getResource("/fxml/login.fxml"));
Stage stage = new Stage();
stage.setScene(new Scene(loader.load()));
LoginController controller = loader.<LoginController>getController();
controller.setUrl(url);
controller.setLoginSuccessTest(loginSuccessTest);
controller.setHandler(handler);
stage.setTitle("Login...");
stage.initModality(Modality.APPLICATION_MODAL);
stage.showAndWait();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
示例2: start
import javafx.scene.web.WebEngine; //导入依赖的package包/类
@Override
public void start(Stage stage) {
stage.setTitle("HTMLEditor Sample");
stage.setWidth(650);
stage.setHeight(500);
Scene scene = new Scene(new Group());
VBox root = new VBox();
root.setPadding(new Insets(8, 8, 8, 8));
root.setSpacing(5);
root.setAlignment(Pos.BOTTOM_LEFT);
final HTMLEditor htmlEditor = new HTMLEditor();
htmlEditor.setPrefHeight(245);
htmlEditor.setHtmlText(INITIAL_TEXT);
final WebView browser = new WebView();
final WebEngine webEngine = browser.getEngine();
ScrollPane scrollPane = new ScrollPane();
scrollPane.getStyleClass().add("noborder-scroll-pane");
scrollPane.setStyle("-fx-background-color: white");
scrollPane.setContent(browser);
scrollPane.setFitToWidth(true);
scrollPane.setPrefHeight(180);
Button showHTMLButton = new Button("Load Content in Browser");
root.setAlignment(Pos.CENTER);
showHTMLButton.setOnAction((ActionEvent arg0) -> {
webEngine.loadContent(htmlEditor.getHtmlText());
});
root.getChildren().addAll(htmlEditor, showHTMLButton, scrollPane);
scene.setRoot(root);
stage.setScene(scene);
stage.show();
}
示例3: getListener
import javafx.scene.web.WebEngine; //导入依赖的package包/类
private ChangeListener<Worker.State> getListener(final DropboxManager.DropboxAccountLinkListener dropboxAccountLinkListener,
final DbxWebAuthNoRedirect webAuth, final WebEngine engine, final Stage stage) {
return (observable, oldValue, newState) -> {
if (newState == Worker.State.SUCCEEDED) {
try {
final String authCode = (String) engine.executeScript("document.getElementById('auth-code').textContent");
LOGGER.debug("Authorization Code [{}]", authCode);
DbxAuthFinish authFinish = webAuth.finish(authCode);
String accessToken = authFinish.accessToken;
final DbxAuthInfo dbxAuthInfo = new DbxAuthInfo(accessToken, DbxHost.Default);
DbxAuthInfo.Writer.writeToFile(dbxAuthInfo, accessTokenFile);
DbxClient client = new DbxClient(dropboxConfig, dbxAuthInfo.accessToken, dbxAuthInfo.host);
final String displayName = client.getAccountInfo().displayName;
LOGGER.info("Linked account [{}]", displayName);
stage.close();
dropboxAccountLinkListener.accountLinked(AccountInfoFactory.getAccountInfo(client.getAccountInfo()));
} catch (Exception e) {
// ignore
}
}
};
}
示例4: createEventHandler
import javafx.scene.web.WebEngine; //导入依赖的package包/类
private EventHandler<WebEvent<String>> createEventHandler() {
return new EventHandler<WebEvent<String>>() {
@Override
public void handle(WebEvent<String> event) {
if (event.getSource() instanceof WebEngine) {
WebEngine engine = (WebEngine) event.getSource();
String url = engine.getLocation();
String code = getResponseValueFromUrl(url);
if (StringUtils.isNotEmpty(code)) {
webEngine.getLoadWorker().cancel();
startCreateOAuth(code);
}
}
}
};
}
示例5: WebViewPane
import javafx.scene.web.WebEngine; //导入依赖的package包/类
public WebViewPane() {
VBox.setVgrow(this, Priority.ALWAYS);
setMaxWidth(Double.MAX_VALUE);
setMaxHeight(Double.MAX_VALUE);
WebView view = new WebView();
view.setMinSize(500, 400);
view.setPrefSize(500, 400);
final WebEngine eng = view.getEngine();
eng.load("http://www.oracle.com/us/index.html");
final TextField locationField = new TextField("http://www.oracle.com/us/index.html");
locationField.setMaxHeight(Double.MAX_VALUE);
Button goButton = new Button("Go");
goButton.setDefaultButton(true);
EventHandler<ActionEvent> goAction = new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent event) {
eng.load(locationField.getText().startsWith("http://") ? locationField.getText() :
"http://" + locationField.getText());
}
};
goButton.setOnAction(goAction);
locationField.setOnAction(goAction);
eng.locationProperty().addListener(new ChangeListener<String>() {
@Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
locationField.setText(newValue);
}
});
GridPane grid = new GridPane();
grid.setVgap(5);
grid.setHgap(5);
GridPane.setConstraints(locationField, 0, 0, 1, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.SOMETIMES);
GridPane.setConstraints(goButton,1,0);
GridPane.setConstraints(view, 0, 1, 2, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.ALWAYS);
grid.getColumnConstraints().addAll(
new ColumnConstraints(100, 100, Double.MAX_VALUE, Priority.ALWAYS, HPos.CENTER, true),
new ColumnConstraints(40, 40, 40, Priority.NEVER, HPos.CENTER, true)
);
grid.getChildren().addAll(locationField, goButton, view);
getChildren().add(grid);
}
示例6: WebViewSample
import javafx.scene.web.WebEngine; //导入依赖的package包/类
public WebViewSample() {
WebView webView = new WebView();
final WebEngine webEngine = webView.getEngine();
webEngine.load(DEFAULT_URL);
final TextField locationField = new TextField(DEFAULT_URL);
webEngine.locationProperty().addListener(new ChangeListener<String>() {
@Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
locationField.setText(newValue);
}
});
EventHandler<ActionEvent> goAction = new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent event) {
webEngine.load(locationField.getText().startsWith("http://")
? locationField.getText()
: "http://" + locationField.getText());
}
};
locationField.setOnAction(goAction);
Button goButton = new Button("Go");
goButton.setDefaultButton(true);
goButton.setOnAction(goAction);
// Layout logic
HBox hBox = new HBox(5);
hBox.getChildren().setAll(locationField, goButton);
HBox.setHgrow(locationField, Priority.ALWAYS);
VBox vBox = new VBox(5);
vBox.getChildren().setAll(hBox, webView);
VBox.setVgrow(webView, Priority.ALWAYS);
getChildren().add(vBox);
}
示例7: initComponents
import javafx.scene.web.WebEngine; //导入依赖的package包/类
private void initComponents() {
webView.setId("webView");
webView.getEngine().getLoadWorker().stateProperty().addListener(new HyperlinkRedirectListener(webView));
VBox.setVgrow(webView, Priority.ALWAYS);
WebEngine engine = webView.getEngine();
if (blurbInfo.getURL() != null)
engine.load(blurbInfo.getURL().toExternalForm());
else
engine.loadContent(blurbInfo.getHtml());
buttonBar.setId("buttonBar");
buttonBar.setButtonMinWidth(Region.USE_PREF_SIZE);
buttonBar.getButtons().add(okButton);
if (blurbInfo.isCancelNeeded()) {
buttonBar.getButtons().add(cancelButton);
}
okButton.setOnAction((e) -> onOk());
cancelButton.setOnAction((e) -> onCancel());
}
示例8: initComponent
import javafx.scene.web.WebEngine; //导入依赖的package包/类
private void initComponent() {
webView = new WebView();
String externalForm = ACEEditor.class.getResource("/Ace.html").toExternalForm();
WebEngine engine = webView.getEngine();
engine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
@Override public void changed(ObservableValue<? extends State> observable, State oldValue, State newValue) {
if (newValue != State.SUCCEEDED) {
return;
}
JSObject window = (JSObject) engine.executeScript("window");
window.setMember("java", ACEEditor.this);
engine.executeScript("console.log = function(message)\n" + "{\n" + " java.log(message);\n" + "};");
ACEEditor.this.engine = engine;
setOptions(new JSONObject().put("showLineNumbers", showLinenumbers).put("firstLineNumber", startLineNumber)
.put("overwrite", false));
loadPreferences();
hookKeyBindings();
}
});
engine.load(externalForm);
ToolBarContainer container = ToolBarContainer.createDefaultContainer(Orientation.RIGHT);
if (withToolbar) {
ToolBarPanel toolBarPanel = container.getToolBarPanel();
createToolBars(toolBarPanel);
}
container.setContent(webView);
this.node = container;
}
示例9: start
import javafx.scene.web.WebEngine; //导入依赖的package包/类
@Override
public void start(Stage stage) {
VBox vbox = new VBox();
Scene scene = new Scene(vbox);
stage.setTitle("Hyperlink Sample");
stage.setWidth(570);
stage.setHeight(550);
selectedImage.setLayoutX(100);
selectedImage.setLayoutY(10);
final WebView browser = new WebView();
final WebEngine webEngine = browser.getEngine();
for (int i = 0; i < captions.length; i++) {
final Hyperlink hpl = hpls[i] = new Hyperlink(captions[i]);
final Image image = images[i] =
new Image(getClass().getResourceAsStream(imageFiles[i]));
hpl.setGraphic(new ImageView (image));
hpl.setFont(Font.font("Arial", 14));
final String url = urls[i];
hpl.setOnAction((ActionEvent e) -> {
webEngine.load(url);
});
}
HBox hbox = new HBox();
hbox.setAlignment(Pos.BASELINE_CENTER);
hbox.getChildren().addAll(hpls);
vbox.getChildren().addAll(hbox, browser);
VBox.setVgrow(browser, Priority.ALWAYS);
stage.setScene(scene);
stage.show();
}
示例10: showOverview
import javafx.scene.web.WebEngine; //导入依赖的package包/类
public void showOverview() {
if (!manager.isCatalogueLoaded() || (manager.groupList() == null || manager.groupList().isEmpty())) {
return;
}
SimpleOverviewBuilder overview = new SimpleOverviewBuilder(manager.getCatalogue(), manager.groupList());
String export = overview.exportOverviewHTML();
WebView view = new WebView();
WebEngine engine = view.getEngine();
engine.loadContent(export);
HBox box = new HBox();
view.prefWidthProperty().bind(box.widthProperty());
view.prefHeightProperty().bind(box.heightProperty());
Scene webScene = new Scene(box, evaluator.getWidth(), evaluator.getHeight());
box.prefWidthProperty().bind(webScene.widthProperty());
box.prefHeightProperty().bind(webScene.heightProperty());
box.getChildren().add(view);
PopupStage popupStage = new PopupStage("Overview", webScene);
popupStage.showAndWait();
}
示例11: start
import javafx.scene.web.WebEngine; //导入依赖的package包/类
@Override
public void start(Stage stage) throws Exception {
TabPane tabPane = new TabPane();
Tab tab1 = new Tab();
tab1.setText("Demos");
tab1.setClosable(false);
SplitPane sp = new SplitPane();
final StackPane sp1 = new StackPane();
sp1.getChildren().add(createTreeView());
final BorderPane sp2 = new BorderPane();
sp2.setCenter(createChartPane());
sp.getItems().addAll(sp1, sp2);
sp.setDividerPositions(0.3f, 0.6f);
tab1.setContent(sp);
tabPane.getTabs().add(tab1);
Tab tab2 = new Tab();
tab2.setText("About");
tab2.setClosable(false);
WebView browser = new WebView();
WebEngine webEngine = browser.getEngine();
webEngine.load(getClass().getResource("/com/orsoncharts/fx/demo/about.html").toString());
tab2.setContent(browser);
tabPane.getTabs().add(tab2);
Scene scene = new Scene(tabPane, 1024, 768);
stage.setScene(scene);
stage.setTitle("Orson Charts JavaFX Demo");
stage.show();
}
示例12: createChartPane
import javafx.scene.web.WebEngine; //导入依赖的package包/类
private SplitPane createChartPane() {
CategoryDataset3D dataset = SampleData.createCompanyRevenueDataset();
Chart3D chart = AreaChart3DFXDemo1.createChart(dataset);
Chart3DViewer viewer = new Chart3DViewer(chart);
this.splitter = new SplitPane();
splitter.setOrientation(Orientation.VERTICAL);
final BorderPane borderPane = new BorderPane();
borderPane.setCenter(viewer);
// Bind canvas size to stack pane size.
viewer.prefWidthProperty().bind(borderPane.widthProperty());
viewer.prefHeightProperty().bind(borderPane.heightProperty());
final StackPane sp2 = new StackPane();
this.chartDescription = new WebView();
WebEngine webEngine = chartDescription.getEngine();
webEngine.load(AreaChart3DFXDemo1.class.getResource("AreaChart3DFXDemo1.html").toString());
sp2.getChildren().add(chartDescription);
splitter.getItems().addAll(borderPane, sp2);
splitter.setDividerPositions(0.70f, 0.30f);
return splitter;
}
示例13: createBrowser
import javafx.scene.web.WebEngine; //导入依赖的package包/类
/**
* @param pane
* @param backButton
* @param forwardButton
*/
public static void createBrowser(final Pane pane, final Button backButton, final Button forwardButton) {
LOGGER.info("Start initialization for a web page");
final WebView browser = new WebView();
final WebEngine webEngine = browser.getEngine();
webEngine.load(PREDEFINED_URL_CNN);
browser.setMaxWidth(pane.getWidth());
browser.setMinHeight(pane.getHeight());
pane.getChildren().add(browser);
initControlsFor(webEngine, backButton, forwardButton);
LOGGER.info("Initialization for a web page is done");
}
示例14: HtmlPage
import javafx.scene.web.WebEngine; //导入依赖的package包/类
public HtmlPage(String link) {
VBox root = new VBox();
Scene scene = new Scene(root);
setTitle("FileSend - Page");
final WebView browser = new WebView();
final WebEngine webEngine = browser.getEngine();
try {
httpsLoad(webEngine, link);
} catch (NoSuchAlgorithmException | KeyManagementException e) {
e.printStackTrace();
}
root.getChildren().add(browser);
VBox.setVgrow(browser, Priority.ALWAYS);
getIcons().add(new Image(getClass().getResourceAsStream(".." + File.separator + "images" + File.separator + "logo.png")));
setScene(scene);
setMaximized(true);
}
示例15: wait
import javafx.scene.web.WebEngine; //导入依赖的package包/类
public static void wait(WebView view) {
Stage stage = new Stage();
WebEngine engine = view.getEngine();
engine.documentProperty().addListener((observable, o, n) -> stage.close());
Scene scene = new Scene(view);
stage.initStyle(StageStyle.UNDECORATED);
stage.setWidth(1);
stage.setHeight(1);
stage.setScene(scene);
stage.showAndWait();
stage.close();
}