javafx - Is there an event when for example to detect when a text field loses focus?
问题描述
I'm trying to find an solution to detect when a TextField
loses focus.
This is some code I have at the moment.
Is there an event just like KeyEvent
or do I need to use an other method?
private void buildGui() {
setVgap(10);
setHgap(10);
setPadding(new Insets(50));
Label lblgb = new Label("Gebruikersnaam:");
Label lblww1 = new Label("Wachtwoord:");
Label lblww2 = new Label("Bevestig wachtwoord:");
txfGebruikersnaam = new TextField();
txfWachtwoord = new TextField();
txfWachtwoord2 = new TextField();
txfGebruikersnaam.setOnMouseExited(new javafx.event.EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
String gebr = txfGebruikersnaam.getText().trim();
if (gebr.matches("\\s")) {
String[] strSplit = gebr.split(" ");
String a = strSplit[0];
String b = strSplit[1];
if (a.length() >= 4 && b.length() >= 8) {
if (!(Character.isUpperCase(a.charAt(0)) && Character.isDigit(b.charAt(b.length() - 1)))) {
errorAlerts("Het eerste woord moet beginnen met een hoofdletter, het 2e moet eindigen met een cijfer!");
}
} else {
errorAlerts("Het eerste woord moet minstens 4 letters lang zijn, het 2e minstens 8!");
}
} else {
errorAlerts("Uw gebruikersnaam moet uit 2 woorden bestaan!");
}
}
});
解决方案
推荐阅读
- python - 格式化部分依赖图
- ffmpeg - FFMPEG 循环不会立即开始
- docker - Dockerfile 无法执行 CMD 命令(docker for windows)
- pdf - 获取 OcspClient 和 CrlClient 以在 LTV 时间戳中使用
- python - 如何根据 Pandas to_html 中的行条件格式化数字
- curl - CURL 无法放置新数据库
- sharepoint - 为列表项创建自动日期捕获和年龄计算
- excel - 将 EAN-13 从 Excel 导入 Access
- content-security-policy - 内容安全策略的默认值是什么?
- mysql - 获取 mysql 表的行,其 varchar 字段的值包含所需的整数