我有一个javafx可编辑的ComboBox。
只有当我按enter,而不仅仅是退出ComboBox时,value属性才会更新。
在我看来,它似乎是一个bug,而不是一个设计特性,因为奇怪的是,一个非聚焦控件显示的值不是它的value属性所反映的。
下面是一个SSCE,它说明了这个问题:
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进行了快速搜索,但没有发现这种行为。(也许我还没注意到)
更新
好的,我刚加了
System.out.println("javafx.runtime.version: " + System.getProperties().get("javafx.runtime.version"));并得到结果:
javafx.runtime.version: 2.1.something我用最后一个可用的版本升级了版本:
javafx.runtime.version: 2.2.3-b05这个问题就消失了。
发布于 2012-11-13 03:00:39
在当焦点离开时,RT-21454 ComboBox值应该更新。中修复的相关错误。
更新
AgostinoX报告说,通过升级到JavaFX 2.2.3-b05解决了这个问题。
您可以通过在javafx应用程序的start方法中放置以下代码来检查所使用的JavaFX版本。
System.out.println("javafx.runtime.version: " + System.getProperties().get("javafx.runtime.version"));https://stackoverflow.com/questions/13353011
复制相似问题