问题
How can an individual column width be forced in a TableView?
Let's say I have a button to reset the width of all my columns to a pre-defined value. My TableView is configured to have UNCONSTRAINED_RESIZE_POLICY
. Right now, if I resize two columns manually and then hit the reset button, nothing happens.
I'm using setPrefWidth()
to set the preferred column width. I even checked the value before and after, it changes as desired. The visual representation, however, stays the same. Is there any possibility to force a real column resize to the desired width? Can I tell my table to re-layout, update or be re-drawn?
Does JavaFX provide a function such as pack()
in SWT to force a component to resize to its preferred width/height?
回答1:
Try to bind the columns width to that of the table:
col1.prefWidthProperty().bind(col1.getTableView().widthProperty().multiply(1.5).divide(2));
col2.prefWidthProperty().bind(col2.getTableView().widthProperty().multiply(0.5).divide(2));
来源:https://stackoverflow.com/questions/27267276/javafx-force-individual-column-width-in-tableview