JavaFX 2 Automatic Column Width

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

    my idea.

    table.getColumns().add(new TableColumn<>("Num") {
        {
            // 15%
            prefWidthProperty().bind(table.widthProperty().multiply(0.15));
        }
    });
    table.getColumns().add(new TableColumn<>("Filename") {{
        // 20%
        prefWidthProperty().bind(table.widthProperty().multiply(.2));
    }});
    table.getColumns().add(new TableColumn<>("Path") {{
        // 50%
        prefWidthProperty().bind(table.widthProperty().multiply(.5));
    }});
    table.getColumns().add(new TableColumn<>("Status") {
        {
            // 15%
            prefWidthProperty().bind(table.widthProperty().multiply(.15));
        }
    });
    

提交回复
热议问题