如何使hbox适合列标题?

时间:2015-10-26 19:29:18

标签: java javafx tableview javafx-8

这是自定义列标题的代码:

private HBox createHeader(int index, String name){
        HBox box = new HBox();
        box.setAlignment(Pos.CENTER);

        TextField headerTextField = new TextField(name);
        headerTextField.textProperty().addListener((observable, oldValue, newValue) -> {
            changeHeaderList(oldValue, newValue);
        });


        final ImageView crossImg = new ImageView("file:res/x.png");
        crossImg.setFitHeight(20d);
        crossImg.setFitWidth(20d);
        crossImg.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent event) -> {
            selectedMatrix.getMatrixRowsArrList().forEach((MatrixRow mr) -> mr.getCells().remove(index));
            selectedMatrix.setNumOfColumns(selectedMatrix.getNumOfColumns() - 1);
            showMatrix(selectedMatrix.getName());
            event.consume();
        });

        box.getChildren().addAll(headerTextField, crossImg);
        return box;
    }

这就是它的名称:

if (editBox.isSelected()) {

    col.setSortable(false);                       
    col.setGraphic(createHeader(i, m.getMatrixRowsArrList().get(0).getCells().get(i)));

它的外观如下:

enter image description here

全屏:

enter image description here

如何让TextField延伸到整个HBox?所以它像第一张照片一样全屏填充。感谢。

1 个答案:

答案 0 :(得分:2)

您可以在HBox的createHeader方法中设置HGrow

SELECT count(*), cdate 
FROM tabl 
GROUP BY YEAR(cdate), MONTH(cdate), DAY(cdate);