我想从FXML中设置TableView的TableView,但是我找不到如何做到这一点。我已经尝试了以下几种方法:
1.只需将其设置为TableView的属性:
<TableView selectionModel="MULTIPLE">2.设置与ListView工作相同的属性(请参见:https://community.oracle.com/thread/2315611?start=0&tstart=0):
<TableView multiSelect="true">3.以不同的方式设置财产:
<TableView>
<selectionModel>
<TableView fx:constant="MULTIPLE" />
</selectionModel>
</TableView>4.另一个版本:
<TableView>
<selectionModel>
<SelectionModel fx:constant="MULTIPLE" />
</selectionModel>
</TableView>5.甄选模式(不同):
<TableView>
<selectionModel>
<SelectionModel selectionModel="MULTIPLE" />
</selectionModel>
</TableView>这些都不管用。
任何帮助都是非常感谢的!
发布于 2014-12-27 18:07:38
如果在FXML上有可能,这应该是这样的方式:
<TableView fx:id="table" prefHeight="200.0" prefWidth="200.0" >
<columns>
<TableColumn prefWidth="75.0" text="C1" />
</columns>
<selectionModel>
<SelectionMode fx:constant="MULTIPLE"/>
</selectionModel>
</TableView>不幸的是,当您运行它时,会得到一个异常:
java.lang.IllegalArgumentException: Unable to coerce SINGLE to class javafx.scene.control.TableView$TableViewSelectionModel.
at com.sun.javafx.fxml.BeanAdapter.coerce(BeanAdapter.java:495)之所以会发生这种情况,是因为bean适配器试图在类javafx.scene.control.TableView$TableViewSelectionModel中找到valueOf of javafx.scene.control.SelectionMode.MULTIPLE,但没有找到它。
对于这个这里,有一个未解决的JIRA票据。
基于该报告,我找到的唯一可行解决方案是使用脚本功能:
...
<?language javascript?>
<TableView fx:id="table" prefHeight="200.0" prefWidth="200.0" >
<columns >
<TableColumn fx:id="col" prefWidth="75.0" text="C1" />
</columns>
</TableView>
<fx:script>
table.getSelectionModel().setSelectionMode(javafx.scene.control.SelectionMode.MULTIPLE);
</fx:script> 这和用代码做这件事一样。
https://stackoverflow.com/questions/27667965
复制相似问题