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

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)));


它是这样的:

java - 如何使hbox适合列标题?-LMLPHP

在全屏模式下:

java - 如何使hbox适合列标题?-LMLPHP

如何使TextField延伸到整个HBox?因此,它就像第一张图片一样全屏显示。谢谢。

最佳答案

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

HBox.setHgrow(headerTextField, Priority.ALWAYS);

关于java - 如何使hbox适合列标题?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33354031/

10-10 14:41