【发布时间】:2012-03-20 14:13:34
【问题描述】:
我正在进行一个项目,我应该使用 JavaFX 2.0 编写登录系统。 现在我正在尝试编写一个与密码字段连接的工具提示,但工具提示根本不显示。我正在使用“javafx-samples-2.0.3”中的 FXML-LoginDemo 项目。然后我尝试使用:http://docs.oracle.com/javafx/2.0/ui_controls/tooltip.htm#BABHCHGG example 19.1.
如果您需要更多代码来查看此问题,请说出来.. 因为我真的不知道问题出在哪里..
到目前为止,这是我的代码:
package demo;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
/**
* Login Controller.
*/
public class LoginController {
@FXML private TextField userId;
@FXML private PasswordField password;
@FXML private Label errorMessage;
@FXML final Tooltip tooltip = new Tooltip();
@FXML protected void processLogin(ActionEvent event) {
tooltip.setText("\nYour password must be\n at least 8 characters in length\n");
password.setTooltip(tooltip);
if(!App.getInstance().userLogging(userId.getText(), password.getText())){
errorMessage.setText("Invalid username or password: " + userId.getText());
}
//Replaces inputed password with an empty String.
password.setText("");
}
}
【问题讨论】: