当用户输入错误的登录名/密码对时,如何使我的javaFX/8对话框更优雅地摇动?
由于java8u40中的对话框没有,我打算自己创建一个.但是,它看起来不够好.
它出什么问题了?有人可以帮忙吗?这样做有更好的方法吗?
public void loginDialog() {
// Create the custom dialog.
Dialog<Pair<String, String>> dialog = new Dialog<>();
dialog.setTitle("Mars Simulation Project");
dialog.setHeaderText("Log in");
dialog.setContentText("Enter your username and password : ");
dialog.initModality(Modality.NONE);
// Set the button types.
ButtonType loginButtonType = new ButtonType("Login", ButtonData.OK_DONE);
dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL);
// Create the username and password labels and fields.
GridPane grid = new GridPane();
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(20, 150, 10, 10));
TextField tfPlayer = new TextField();
tfPlayer.setPromptText("e.g. m03j");
PasswordField tfPassword = new PasswordField();
tfPassword.setPromptText("xxxx");
Button defaultPWB …Run Code Online (Sandbox Code Playgroud) Java能够一次创建多个EDT吗?
我正在尝试设置EDT以及如何更新"重型"面板的内容,其中可能有十几个面板嵌入其中并且共有数百个组件.目前我有
public void run() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
panel.update();
}
});
}
Run Code Online (Sandbox Code Playgroud)
我查看了以下帖子:
http://en.wiki2.org/wiki/Event_dispatching_thread
等等.
我有点明白,如果有一个EDT必须处理的十几个事件,Java已经有了一个内部调度机制来对这些事件进行分组/优先级排序.
根据http://docs.oracle.com/javase/tutorial/uiswing/concurrency/dispatch.html
"This is necessary because most Swing object methods are not "thread safe": invoking them from multiple threads risks thread interference or memory consistency errors."
Run Code Online (Sandbox Code Playgroud)
那么如果我用新线程创建第二个EDT(下面的新Runnable(){...} .start()怎么办?
为了避免线程安全,java会自动将两个EDT合并为一个吗?
new Thread(new Runnable() {
public void run() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
panel.update();
}
});
}
}).start();
Run Code Online (Sandbox Code Playgroud)