我创建了这个非常简单的JavaFX Web浏览器示例。
StackPane secondaryLayout = new StackPane();
Scene secondScene = new Scene(secondaryLayout, 200, 100);
Stage secondStage = new Stage();
secondStage.setTitle("Second Stage");
secondStage.setScene(secondScene);
WebView browser = new WebView();
WebEngine engine = browser.getEngine();
String url = "http://zoranpavlovic.blogspot.com/";
engine.load(url);
StackPane sp = new StackPane();
sp.getChildren().add(browser);
Scene root = new Scene(sp, 600, 600);
secondStage.setScene(root);
secondStage.show();
我想将输入字段添加到窗口大小和按钮“Go”。你能帮我实现吗?
答案 0 :(得分:0)
您可以拥有带文本字段和按钮的HBox,按钮的操作可以加载Web引擎。
我使用记事本编写了代码,因此错误可能会在
中出现StackPane secondaryLayout = new StackPane();
场景secondScene =新场景(secondaryLayout,200,100);
Stage secondStage = new Stage();
secondStage.setTitle("Second Stage");
secondStage.setScene(secondScene);
HBox box = new HBox();
TextField textField = new TextField();
Button go = new Button();
box.getChildren.addAll(textField, go);
WebView browser = new WebView();
WebEngine engine = browser.getEngine();
go.setOnAction(new Eventhandler<ActionEvent>(){
@Override public void handle(ActionEvent e) {
String url = textField.getText();
engine.load(url);
}
});
BorderPane sp = new BorderPane();
sp.setTop(box);
sp.setCenter(browser);
Scene root = new Scene(sp, 600, 600);
secondStage.setScene(root);
secondStage.show();