首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >javafx-2,仅在enter键上设置可编辑的ComboBox值。

javafx-2,仅在enter键上设置可编辑的ComboBox值。
EN

Stack Overflow用户
提问于 2012-11-12 22:59:04
回答 1查看 2.6K关注 0票数 3

我有一个javafx可编辑的ComboBox。

只有当我按enter,而不仅仅是退出ComboBox时,value属性才会更新。

在我看来,它似乎是一个bug,而不是一个设计特性,因为奇怪的是,一个非聚焦控件显示的值不是它的value属性所反映的。

下面是一个SSCE,它说明了这个问题:

代码语言:javascript
复制
import javafx.application.Application;
import javafx.beans.*;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class T02 extends Application {

public static void main (String [] args) { launch(args); }

@Override public void start(Stage stage) throws Exception {

    System.out.println("javafx.runtime.version: " + System.getProperties().get("javafx.runtime.version"));

    VBox vbox = new VBox();

    //this combobox is the object of the investigation
    final ComboBox comboBox = new ComboBox();
    comboBox.setEditable(true);
    vbox.getChildren().add(comboBox);

    //I need another component just to allow the ComboBox to loose the focus
    TextField textField = new TextField();
    vbox.getChildren().add(textField);

    //And here it is: when comboBox looses focus, i print its state
    comboBox.focusedProperty().addListener(new InvalidationListener() {
        @Override public void invalidated(Observable observable) {
            //return if it has the focus: i am just interested on focus lost
            if (comboBox.focusedProperty().get()) {return;}
            System.out.println(comboBox.getValue());
        }
    } );

    stage.setScene(new Scene(vbox));
    stage.show();
}

}

产出:

在组合框上写一些东西,然后单击另一个控件(或者按下选项卡,它是相同的)

单击组合框上的“上一步”,按回车键,然后单击“文本”字段。

你好

第一个空值很奇怪,也许像我之前说过的那样是有问题的。我对jira进行了快速搜索,但没有发现这种行为。(也许我还没注意到)

更新

好的,我刚加了

代码语言:javascript
复制
System.out.println("javafx.runtime.version: " + System.getProperties().get("javafx.runtime.version"));

并得到结果:

代码语言:javascript
复制
javafx.runtime.version: 2.1.something

我用最后一个可用的版本升级了版本:

代码语言:javascript
复制
javafx.runtime.version: 2.2.3-b05

这个问题就消失了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-13 03:00:39

当焦点离开时,RT-21454 ComboBox值应该更新。中修复的相关错误。

更新

AgostinoX报告说,通过升级到JavaFX 2.2.3-b05解决了这个问题。

您可以通过在javafx应用程序的start方法中放置以下代码来检查所使用的JavaFX版本。

代码语言:javascript
复制
System.out.println("javafx.runtime.version: " + System.getProperties().get("javafx.runtime.version"));
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13353011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档