JavaFX: Force individual column width in TableView

筅森魡賤 提交于 2019-12-13 03:04:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!