javafx - 如何在输入时在微调器文本字段中选择数字或文本?
问题描述
我正在为整数使用 javafx 微调器。当我单击它或使用 TAB 移动到它时,有没有办法在 Spinner 中选择值?就像它适用于具有以下代码的 TextAreas 一样:
myTextArea.focusedProperty().addListener((obs, isFocused, isNowFocused) -> {
if (isNowFocused) {
myTextArea.selectAll();
}
})
selectAll() 不适用于微调器。我想在不删除初始值的情况下开始输入微调器字段。
解决方案
您可以selectAll()
调用TextField
.Spinner
spinner.focusedProperty().addListener((obs, wasFocused, isFocused) -> {
if (isFocused) {
Platform.runLater(spinner.getEditor()::selectAll);
}
});
尝试此操作时,我必须将呼叫包装在selectAll
呼叫中Platform.runLater
。当Spinner
它获得干扰调用的焦点时,它本身可能正在做某事selectAll
;usingPlatform.runLater
将调用推迟到Spinner
执行任何操作之后的某个时间。
推荐阅读
- python - NGINX 在 Dockered Django 项目(Nginx、Django、Docker)中找不到媒体文件
- javascript - React-Helmet 中的隐藏类有什么作用?
- c# - 按关键字拆分文件
- ios - UITableViewCell 圆角对于某些单元格不可见
- bash - Bash循环一个curl请求,输出到文件并停止直到空响应
- prometheus - 如何将我的 Prometheus 上的指标/日志发送到 Grafana?
- android - 在发布模式下,无法在 Android 上使用 firebase auth 登录。调试模式正常。代码=10,消息=10,mPendingCredential=null
- r - 计算R中具有相似值的行的平均值
- php - 在 apache 中提供从 git 克隆的内容
- integer - 为什么这个整数奇偶校验优化在 GLSL 中失败了?