Per*_*eel 20 combobox selectionmodel javafx-2 javafx-8
我在javafx2.2中偶然发现了Comboboxes的一个问题.这是场景:
此窗格包含6个组合框.其中三个有固定项:cboReport,cboSales,cboSend.其中三个从db(ObservableList)获取数据,并在窗格变为可见时填充:cboFile,cboCustomer,cboVet
窗口关闭时,窗格上的数据将通过resetGUI_editFilePane()方法重置.有像这样的行:
...
cboReport.getSelectionModel().clearSelection();
cboSales.getSelectionModel().clearSelection();
cboSend.getSelectionModel().clearSelection();
cboFile.getSelectionModel().clearSelection();
cboCustomer.getSelectionModel().clearSelection();
cboVet.getSelectionModel().clearSelection();
cboFile.getItems().clear();
cboCustomer.getItems().clear();
cboVet.getItems.clear();
...
Run Code Online (Sandbox Code Playgroud)
当用户通过按下"editFile"按钮再次打开窗格时,我注意到只有"固定项目"组合框已经清除了它们的选择,动态填充的组合框显示最后选择的项目,尽管选择本身的值是null.这看起来像是一个图形错误或我做错了什么?
有没有解决这个问题的方法或重置组合框的最佳方法是什么?
编辑2014/08/27:
这是正式的错误(clearSelection()不清楚值):https:
//bugs.openjdk.java.net/browse/JDK-8097244
官方的"解决方法"是清除选择后清除ComboBox的值.
cb.getSelectionModel().clearSelection();
// Clear value of ComboBox because clearSelection() does not do it
cb.setValue(null);
Run Code Online (Sandbox Code Playgroud)
小智 20
这很简单.您只需使用ComboBox的value属性即可.干得好 ....
ComboBox c;
c.valueProperty().set(null);
Run Code Online (Sandbox Code Playgroud)
我希望这适合你:-D
Bre*_*dan 18
我遇到了几乎完全相同的情况,并在寻找解决方案时遇到了你的问题.幸运的是,我想出了一个强制ComboBoxes重置的解决方法.重置窗格中的数据时,而不是执行以下操作:
cboVet.getSelectionModel().clearSelection();
cboVet.getItems.clear();
Run Code Online (Sandbox Code Playgroud)
做这样的事......
parentNode.getChildren().remove(cboVet);
cboVet = new ComboBox(); // do whatever else you need to format your ComboBox
parentNode.add(cboVet);
Run Code Online (Sandbox Code Playgroud)
您还需要在ComboBox上再次执行setItems(),以便填充新的.这不是一个理想的解决方案,但它似乎正在工作,因为我期望提供clearSelection()方法.
您可以检索项目并将其全部删除:
cboVet.getItems().removeAll(cboVet.getItems());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
39651 次 |
| 最近记录: |