JavaFX TableView custom cell rendering split menu button

前端 未结 1 788
眼角桃花
眼角桃花 2021-01-27 11:12

i\'ve a problem with a custom cell render in a java fx table view component. I\'m able to render the split menu button, but is only rendered from second row of table.

相关标签:
1条回答
  • 2021-01-27 11:52

    Cause you have use the same button in every cell, So it's set a button only last of the cell Value.

    Remove this line in SplitMenuButtonApp class

     SplitMenuButton actions = sMBtn.buildButton();
    

    And replace this line

    aCol.setCellFactory(new ButtonCellFactory<>(actions));

    To below code

    Callback<TableColumn<Contact, SplitMenuButton>, TableCell<Contact, SplitMenuButton>> actionsCol = new Callback<TableColumn<Contact, SplitMenuButton>, TableCell<Contact, SplitMenuButton>>() {
                    @Override
                    public TableCell call(final TableColumn<Contact, SplitMenuButton> param) {
                        final TableCell<Contact, SplitMenuButton> cell = new TableCell<Contact, SplitMenuButton>() {
                            SplitMenuButton actions = sMBtn.buildButton();
                            @Override
                            public void updateItem(SplitMenuButton item, boolean empty) {
                                super.updateItem(item, empty);
                                if (empty) {
                                    setGraphic(null);
                                    setText(null);
                                } else {
                                    setGraphic(actions);
                                    setText(null);
                                }
                            }
                        };
                        return cell;
                }
     };
    
    aCol.setCellFactory(actionsCol);
    

    I hope this code is working for you:)

    0 讨论(0)
提交回复
热议问题