我建议的第一件事就是创建自己的简单对话框。 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();' –