2014-02-10 58 views
0

導航輸入我創造了這個非常簡單的JavaFX web瀏覽器的一個例子。加入申請到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(); 

我想添加輸入字段到窗口的大小和按鈕「去」。你能幫我實施嗎?

回答

0

你可以有一個文本框一個HBox中和一個按鈕,按鈕的動作,你可以加載webengine。

我寫使用記事本的代碼,所以錯誤可能在

StackPane secondaryLayout =新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();