2013-09-28 27 views
0

我是javaFX的新手。我正在javaFX中啓動一個應用程序。我想知道哪些適合啓動應用程序。如何創建javaFX應用程序視圖

我的第一個屏幕是一個有兩個字段(選擇選項字段和文本字段自動填充)的表單。 底部的按鈕(點擊按鈕彈出窗體將打開,以及如何打開javafx中的彈出窗口)。

這對此更好。

  • 在javaFX中創建整個視圖。
  • 在fxml文件中創建。或
  • 創建一個html視圖並加載它。

在此先感謝!

回答

0

我建議你去FXML文件,因爲在此您可以加載CSS文件也是其容易過於

這是一個簡單的彈出演示程序

public class PopupTest extends Application { 

    public static void main(String[] args) { 
     Application.launch(args); 
    } 

    @Override 
    public void start(Stage stage) { 
     Group root = new Group(); 
     Scene scene = new Scene(root, 800, 600); 

     Button btn = new Button("Display Popup"); 
     btn.setOnMouseClicked(new PopupOpenEvent(stage)); 
     root.getChildren().add(btn); 

     stage.setTitle("Popup demo"); 
     stage.setScene(scene); 
     stage.show(); 
     //stage.setVisible(true);  
    } 

    class PopupOpenEvent implements EventHandler<MouseEvent> { 

     private Stage stage; 

     PopupOpenEvent(Stage s){ 
      stage = s; 
     } 

     @Override 
     public void handle(MouseEvent e) { 
      Popup popup = new Popup(); 

      HBox box = new HBox(); 
      box.getChildren().add(new Label("In popup...")); 
      box.setPrefSize(100, 100); 
      box.setAlignment(Pos.BOTTOM_RIGHT); 
      box.setStyle("-fx-background-color: gray;"); 

      popup.getContent().add(box);   
      popup.setX(e.getScreenX()); 
      popup.setY(e.getScreenY()); 
      popup.show(stage); 
     }  
    } 
} 
+0

謝謝,我想知道,如果我去尋找html(這很容易創建UI部分),那麼會產生什麼後果以及如何處理請求表單視圖。 –

+0

感謝寶貴的回答,我想知道一件事請。點擊按鈕怎麼能打開一個彈出窗口。 –

+0

Atleast請告訴我關於popup的解決方案。 –

相關問題