Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
组合框setValue JavaFX_Java_Combobox_Javafx_Fxml - Fatal编程技术网

组合框setValue JavaFX

组合框setValue JavaFX,java,combobox,javafx,fxml,Java,Combobox,Javafx,Fxml,我有一个组合框,我在初始化节点时为这个组合框设置了默认值。但是,一旦从数据库检索到一些数据,我想将这个默认值更新为其他值 initialise() { businessDateComboBox.setItems(config.retrievedPositionsData().getDistinctBusinssDate()); businessDateComboBox.setValue(config.retrievedPositionsData().getCurrentBusinessDate

我有一个组合框,我在初始化节点时为这个组合框设置了默认值。但是,一旦从数据库检索到一些数据,我想将这个默认值更新为其他值

initialise() {
businessDateComboBox.setItems(config.retrievedPositionsData().getDistinctBusinssDate()); 
businessDateComboBox.setValue(config.retrievedPositionsData().getCurrentBusinessDate().toString());
}
setItems是一个ObservableList,setValue是一个ObservableList,但我将其转换为string

现在我使用一个单独的线程从数据库中检索项目

public void readPositionsFromDataBase() throws Exception {
    Task<Integer> task = new Task<Integer>() {
        @Override protected Integer call() throws Exception {       
            config.positionViewPersister().readDataFromDataBase(null,null);
            return 0;
        }
    };
    Thread th = new Thread(task);
    th.setDaemon(true);
    th.start();
config.retrievedPositionsData().setCurrentBusinessDate("56")    
}
public void readPositionsFromDataBase()引发异常{
任务=新任务(){
@重写受保护的整数调用()引发异常{
config.positionViewPersister().readDataFromDataBase(null,null);
返回0;
}
};
线程th=新线程(任务);
th.setDaemon(true);
th.start();
config.retrievedPositionsData().setCurrentBusinessDate(“56”)
}
完成后,我想用为默认组合框值检索的最新值更新用户界面。我通过重新加载FXML和FXML的相应控制器来实现这一点,FXML由initialise方法组成-当前initialise方法再次运行,但用户界面不会使用最新值进行更新。有人知道为什么吗

用户界面中组合框的默认值现在应该是56,因为我已经设置好了。当我打印businessDateComboBox.getValue()时,它给出了56,只是没有更新用户界面


有没有类似于swing重画之类的东西

businessDateComboBox.setValue
用于可编辑的
组合框的编辑组件。我想你的不是,所以正确的方法应该是通过
SelectionModel

businessDateComboBox.getSelectionModel().select(...)

我没有getSelectionModel下的setSelectedItem选项。但是我使用了selectLast,但这并没有完全更新UI?对不起,这是指
select()
。编辑了答案。如果两者都不起作用,那么代码中的其他部分就不起作用了。例如:通过FXML重新加载整个GUI似乎是不必要的。
setValue(…)
select(…)
只有在您传入的值是列表中的一个元素时才起作用(无论如何,这应该是有意义的)。对于您提供的代码,这看起来不太可能;如果列表是
String
s的列表,则
toString()
是多余的。您提供的
组合框
可观察列表
的类型是什么?James_D:这是一个字符串列表,但setValue只接受一个字符串而不是列表。于是谈话开始了。也许我会传入一个与列表中的值相似的值?值必须匹配还是类型必须匹配?如果调用
select(xyz)
,则对象
xyz
必须与
组合框的支持列表中的对象
equals()
完全相同。