我有以下想法:如何將ControlsFX(對話框)與FXML文件一起使用?
- 我想用ControlsFX:漂亮的UI,對於對話的良好支持。
- 我想使用FXML作爲用戶界面的源代碼:場景生成器很好地工作,快速創建和更改。
現在我面臨使用ControlsFX和由FXML文件創建的UI一起的問題。這裏是源代碼:
public class ConfigUI {
private Dialog dlg;
@FXML
TextField urlRepository;
protected Action showConfigDialog() throws IOException {
dlg = new Dialog(null, "Configuration Dialog for Check SVN");
Node content = null;
content = FXMLLoader.load(getClass().getResource("check-dialog.fxml"));
dlg.setResizable(false);
dlg.setIconifiable(false);
dlg.setContent(content);
dlg.getActions().addAll(Dialog.Actions.OK, Dialog.Actions.CANCEL);
return dlg.show();
}
相應FXML文件check-dialog.fxml
如下:
<AnchorPane id="AnchorPane" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="ConfigUI">
<children>
<Label layoutX="29.0" layoutY="26.0" text="URL of Repository" />
<Label layoutX="29.0" layoutY="76.0" text="Revision Interval" />
<TextField fx:id="urlRepository" layoutY="23.0" prefWidth="200.0" AnchorPane.leftAnchor="170.0" AnchorPane.rightAnchor="10.0" />
<Slider fx:id="revIntervalLow" layoutY="77.0" prefWidth="196.0" AnchorPane.leftAnchor="170.0" AnchorPane.rightAnchor="234.0" />
...
</children>
</AnchorPane>
當我現在開始通過下面的代碼的對話框中,TextField urlRepository
的@FXML不起作用:
public void configureActionTrigger(ActionEvent actionEvent) {
ConfigUI ui = new ConfigUI();
Action result = ui.showConfigDialog();
...
}
在調試器中,我看到屬性urlRepository
從不綁定。我在這裏錯過了什麼?是否有必要擁有一個應用程序類和一個控制器類,並且應用程序類構建了UI,然後綁定控制器?
在互聯網上有沒有一個例子可以解釋一個非平凡的例子中ControlsFX和FXML文件如何一起使用?
不錯,我會盡快回到我的電腦上工作。現在我明白了FXML,生成器和控制器的作用要好得多。是否有可用的權威資源? – mliebelt
當我按照你的建議,我得到一個異常:'javafx.fxml.LoadException:已經指定的控制器值.'。但通過重建整體,我可以爲我解決它。 – mliebelt