3

FXML から TableView の SelectionModel を設定したいのですが、これを行う方法が見つかりません。私はすでに次のことを試しました:

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>

これはどれも機能しません。

どんな助けでも大歓迎です!

4

1 に答える 1

8

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 アダプターが反射的に of のクラスを見つけようとするが、javafx.scene.control.TableView$TableViewSelectionModel見つからvalueOfない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> 

これは、コードで行うのと同じです...

于 2014-12-27T18:07:38.293 に答える