JavaFx 2 create TableView with single column

后端 未结 1 783
深忆病人
深忆病人 2020-12-10 16:19

I am trying to create a table with a single column using the following code :

TableView table = new TableView();
table.getColumns         


        
相关标签:
1条回答
  • 2020-12-10 16:55

    I recall that tried to "remove" blank columns myself by playing with css properties in the past without luck. The workaround was either,
    - set the pref width of the cityColumn to cover whole space manually:

    TableColumn<String, String> cityColumn = new TableColumn<String, String>("City Name");
    cityColumn.setPrefWidth(table.getPrefWidth() - 2);
    

    -2 for border widths. Also you can bind column width property to table width property directly, resulting the col width is updated automatically when the table width is resized. See this answer https://stackoverflow.com/a/10152992/682495.
    Or,
    - set the column resize policy to CONSTRAINED_RESIZE_POLICY:

    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    
    0 讨论(0)
提交回复
热议问题