FXML set TableView column resize policy
Asked Answered
Z

1

10

How can I set a TableView's resize policy from FXML? I tired this way, but it's not working:

<TableView layoutX="20.0" layoutY="20.0" prefWidth="674.0" prefHeight="668.0" fx:id="tableView" fx:constant="CONSTRAINED_RESIZE_POLICY">
    <columns>
        <TableColumn text="First Name" />
        <TableColumn text="Last Name" />
        <TableColumn text="Email Address" />
    </columns>    
</TableView>
Zippy answered 30/12, 2012 at 23:18 Comment(0)
J
16

To set columnresize policy for tableview using fxml , you have to use <columnResizePolicy> tag . This will work on javafx 2.2 and later..

<TableView>
  <columnResizePolicy><TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/></columnResizePolicy>
</TableView>

Reference :

Defining TableView columnResizePolicy property with fxml

Jacobsen answered 31/12, 2012 at 22:41 Comment(3)
Thanks it works! Thats a damn "interresting" syntax here. I see why they used that way but well, it's ugly. But works... :)Zippy
If I use the tag as you proposed I get the error message "Unable to coerce javafx.scene.control.TableView to javafx.util.Callback" in my FXML editor. Any hint?Kimmie
This seems to only prevent setting column prefWidths now, and does not prevent user resizingElementary

© 2022 - 2024 — McMap. All rights reserved.