MVC 应用程序的 JavaFX 文件选择器

JavaFX File Chooser for an MVC Application

AFAIK,JavaFX 在场景 Builder/FXML 中没有 FileChooser 组件。需要使用Java、javafx.stage.FileChooserclass来设置。什么是 MVC 应用程序的最佳方式 - 我的所有视图都在 FXML 中?

谢谢。

Could you give me an example of FileChooser in FXML? cc @mrmcwolf

<?import javafx.scene.layout.GridPane?>
<?import javafx.stage.FileChooser?>

<GridPane fx:controller="sample.Controller" xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
    <fx:define>
        <FileChooser fx:id="chooser"/>
    </fx:define>

</GridPane>
public class Controller {
    @FXML
    private FileChooser chooser;

}

fx:define 声明的对象未放置在生成的视图中,但可以通过 id.

在控制器和/或其他声明中访问