2014-07-16 100 views
1

controlfx對話框,我怎麼能在FXML控制器打開一個對話框,因爲它需要stage的JavaFX如何FXML控制器

Dialogs.create() 
    .owner(---what should i write here---) 
    .title("Information Dialog") 
    .masthead("Look, an Information Dialog") 
    .message("I have a great message for you!") 
    .showInformation(); 

我加入以下jar

controlsfx-8.0.6_20.jar 
controlsfx-samples-8.0.6_20.jar 
fxsampler-1.0.6_20.jar 

請幫助我。

回答

1

所有者階段該對話窗口將使用:

import org.controlsfx.dialog.Dialogs; 
import javafx.application.Application; 
import javafx.stage.Stage; 

public class Diag extends Application{ 

    @Override 
    public void start(Stage primaryStage) throws Exception { 
     Dialogs.create() 
     .owner(primaryStage) 
     .title("Information Dialog") 
     .masthead("Look, an Information Dialog") 
     .message("I have a great message for you!") 
     .showInformation(); 
    } 
    public static void main(String[] args) { 
     launch(args); 
    } 

} 

而且,你可能要稱呼其爲一個對話框,您不妨將其稱爲:

 Dialogs.create() 
     .owner(new Stage()) 
     .title("Information Dialog") 
     .masthead("Look, an Information Dialog") 
     .message("I have a great message for you!") 
     .showInformation(); 
相關問題