JavaFX architecture in building dynamic “rows”

后端 未结 1 1006
时光说笑
时光说笑 2021-01-29 02:27

I have an application that I am building that has a table in it, I\'m not using a tableview to build this table because I need each row to be able to expand similar to an accord

相关标签:
1条回答
  • 2021-01-29 03:05

    I can't comment but it may be an answer anyway. Why can't you use the setGraphic method of a custom table cell and put the accordion node in a table. setGraphic takes any kind of node.

    It sounds simpler than what you're doing.

    I just tried it out with the Oracle sample and it works great. I added

        Callback<TableColumn<Person, String>, TableCell<Person, String>> accCellFactory
                = new Callback<TableColumn<Person, String>, TableCell<Person, String>>() {
                    @Override
                    public TableCell call(TableColumn p) {
                        TitledPane t1 = new TitledPane("T1", new Button("B1"));
                        TitledPane t2 = new TitledPane("T2", new Button("B2"));
                        TitledPane t3 = new TitledPane("T3", new Button("B3"));
                        Accordion accordion = new Accordion();
                        accordion.getPanes().addAll(t1, t2, t3);
                        TableCell tc = new TableCell();
                        tc.setGraphic(accordion);
                        return tc;
                    }
                };
    

    and changed this line firstNameCol.setCellFactory(accCellFactory);

    and I get

    Table accordion sample

    Of course you might want something other than buttons but I just copied the Accordion sample from the javadoc.

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