JavaFX 2 Automatic Column Width

前端 未结 8 851
盖世英雄少女心
盖世英雄少女心 2020-11-29 01:09

I have a JavaFX 2 table that is displaying contact details for people, lets imagine there are three columns: first name, last name and email address. When my application sta

8条回答
  •  甜味超标
    2020-11-29 01:34

    If you had 4 columns and only last column needed to expand to fill the rest of the table width and the other columns remained the size I set in Scene Builder.

    double width = col1.widthProperty().get();
    width += col2.widthProperty().get();
    width += col3.widthProperty().get();
    
    col4.prefWidthProperty().bind(table.widthProperty().subtract(width));
    

    Or if you had 2 columns that needed to expand then.

    double width = col1.widthProperty().get();
    width += col3.widthProperty().get();
    
    col2.prefWidthProperty().bind(table.widthProperty().subtract(width).divide(2));
    col4.prefWidthProperty().bind(table.widthProperty().subtract(width).divide(2));
    

提交回复
热议问题