JavaFX 2 Automatic Column Width

前端 未结 8 846
盖世英雄少女心
盖世英雄少女心 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:35

    If your total number of columns are pre-known. You can distribute the column widths among the tableview's width:

    nameCol.prefWidthProperty().bind(personTable.widthProperty().divide(4)); // w * 1/4
    surnameCol.prefWidthProperty().bind(personTable.widthProperty().divide(2)); // w * 1/2
    emailCol.prefWidthProperty().bind(personTable.widthProperty().divide(4)); // w * 1/4
    

    In this code, the width proportions of columns are kept in sync when the tableview is resized, so you don't need to do it manually. Also the surnameCol takes the half space of the tableview's width.

提交回复
热议问题