我建議的第一件事就是創建自己的簡單對話框。 controlsFX的東西很酷,但我的經驗是,一些控件過於複雜,其他人有錯誤。這是一個簡略的例子。
public class DialogBox {
private static String[] login;
public static String[] display(String title, String message) {
Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle(title);
window.setWidth(300);
window.setHeight(175);
window.initStyle(StageStyle.UTILITY);
Label label = new Label(message);
// Set up the JavaFX button controls and listeners and the text fields
// for the login info. The button listeners set the login values
window.setScene(new Scene(root, 300, 175);
window.showAndWait();
return login;
}
}
正如你可以看到,有()稱爲顯示,單一的靜態方法,它返回一個包含用戶登錄信息的字符串數組。只需按如下方式對此方法進行靜態調用即可。
String[] login = DialogBox.display("Login Dialog", "Enter User Name and Password");
什麼'UrStageDialogObj.showDialog();'然後'UrStageDialogObj.setMessage(用戶名)'和'UrStageDialogObj.close();' –