2016-09-02 7 views
0

FXMLでTableViewのサイズを変更することは可能ですか? 私はそれがコードで可能であることを知っていますが、私は特にFXMLのアプローチを探しています。FXMLでTableColumnsに相対幅を与える方法は?

これは現在のアプローチです:

<BorderPane xmlns:fx="http://javafx.com/fxml"> 
    <fx:define> 
     <Double fx:id="tableViewWidth" fx:value="600"/> 
    </fx:define> 
    <center> 
     <TableView fx:id="expensesTableView" editable="true" prefWidth="${tableViewWidth}"> 
      <columnResizePolicy> 
       <TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /> 
      </columnResizePolicy> 
      <columns> 
       <TableColumn text="Title" prefWidth="${tableViewWidth * 3}"> 
        <cellValueFactory> 
         <PropertyValueFactory property="title" /> 
        </cellValueFactory> 
       </TableColumn> 
       <TableColumn text="Category" prefWidth="${tableViewWidth * 3}"> 
        <cellValueFactory> 
         <PropertyValueFactory property="category" /> 
        </cellValueFactory> 
       </TableColumn> 
       <TableColumn text="Period" prefWidth="${tableViewWidth * 2}"> 
        <cellValueFactory> 
         <PropertyValueFactory property="period" /> 
        </cellValueFactory> 
       </TableColumn> 
       <TableColumn text="Value" prefWidth="${tableViewWidth * 2}"> 
        <cellValueFactory> 
         <PropertyValueFactory property="value" /> 
        </cellValueFactory> 
       </TableColumn> 
      </columns> 
     </TableView> 
    </center> 
</BorderPane> 

乗算部分が動作するようには思えません。

+0

は、あなたの質問にコードを修正してください。なぜあなたは 'Double'(これは観測できず、値を変更しない)にバインドしようとしていますか? 「うまくいかない」とはどういう意味ですか?実際に何が起こるのですか? –

+0

@ James_D考え方は、整数をカンマ番号に乗算することではありませんでしたが、それは本当に重要ではありませんでした。どのような観察可能な価値が働くために必要なのでしょうか? Becuase Integerプロパティは、そのように動作するだけではありません。 当然、何も起こりません。 :/私が書いたコードは、実際のアプローチよりもアイデアです。 – codepleb

+0

[コメントセクション](リンク先はhttp://stackoverflow.com/questions/28428280/how-to-set-column-width-in-tableview-in-javafx/28439105?noredirect=1#comment65920465_28439105)それをするために。どうしてそんなことをしないの?私は "Integerのプロパティがちょうどそのように動作しない"という意味を持っていません。あなたのコードを修正してください。すべてが重複していて、 '}'が足りなくなっています。 –

答えて

4

サイズ変更ポリシーを削除する必要があります。また、一部の倍長定数の代わりにTableViewの幅にバインドする必要があります。

さらに結合するために使用される式の一部が構文的に間違っている...

<?xml version="1.0" encoding="UTF-8"?> 

<?import javafx.scene.control.*?> 
<?import javafx.scene.layout.*?> 
<?import javafx.scene.control.cell.*?> 

<BorderPane xmlns:fx="http://javafx.com/fxml"> 
    <center> 
     <TableView fx:id="expensesTableView" editable="true" prefWidth="600"> 
      <columns> 
       <TableColumn text="Title" prefWidth="${expensesTableView.width*0.3}"> 
        <cellValueFactory> 
         <PropertyValueFactory property="title" /> 
        </cellValueFactory> 
       </TableColumn> 
       <TableColumn text="Category" prefWidth="${expensesTableView.width*0.3}"> 
        <cellValueFactory> 
         <PropertyValueFactory property="category" /> 
        </cellValueFactory> 
       </TableColumn> 
       <TableColumn text="Period" prefWidth="${expensesTableView.width*0.2}"> 
        <cellValueFactory> 
         <PropertyValueFactory property="period" /> 
        </cellValueFactory> 
       </TableColumn> 
       <TableColumn text="Value" prefWidth="${expensesTableView.width*0.2}"> 
        <cellValueFactory> 
         <PropertyValueFactory property="value" /> 
        </cellValueFactory> 
       </TableColumn> 
      </columns> 
     </TableView> 
    </center> 
</BorderPane> 
関連する問題