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>
Lakatos Gyula
  • 3,949
  • 7
  • 35
  • 56

1 Answers1

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

invariant
  • 8,758
  • 9
  • 47
  • 61
  • 1
    Thanks it works! Thats a damn "interresting" syntax here. I see why they used that way but well, it's ugly. But works... :) – Lakatos Gyula Dec 31 '12 at 23:33
  • 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? – mwalter May 26 '13 at 20:56
  • This seems to only prevent setting column prefWidths now, and does not prevent user resizing – Greg Rozmarynowycz Mar 26 '16 at 18:33