Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FXML set TableView column resize policy

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>
like image 940
Lakatos Gyula Avatar asked Dec 30 '12 23:12

Lakatos Gyula


People also ask

What does TableView refresh do?

Calling refresh() forces the TableView control to recreate and repopulate the cells necessary to populate the visual bounds of the control. In other words, this forces the TableView to update what it is showing to the user.

What is setCellValueFactory?

setCellValueFactory. public final void setCellValueFactory(Callback<TableColumn.CellDataFeatures<S,T>,ObservableValue<T>> value) Sets the value of the property cellValueFactory. Property description: The cell value factory needs to be set to specify how to populate all cells within a single TableColumn.

What is TableView in JavaFX?

The TableView class provides built-in capabilities to sort data in columns. Users can alter the order of data by clicking column headers. The first click enables the ascending sorting order, the second click enables descending sorting order, and the third click disables sorting. By default, no sorting is applied.

What is PropertyValueFactory in JavaFX?

public PropertyValueFactory(String property) Creates a default PropertyValueFactory to extract the value from a given TableView row item reflectively, using the given property name. Parameters: property - The name of the property with which to attempt to reflectively extract a corresponding value for in a given object.


1 Answers

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

like image 114
invariant Avatar answered Sep 29 '22 15:09

invariant