0

I am trying to create an table which contains an column with one header but has several entries per row in JavaFX 8. The result should look more or less like this:

enter image description here

I tried to add subcolumns which works perfectly, but i was not able to hide the headers of the subcolums. I found solutions to hide the header only for older versions of javafx and for ListView.

Also i tried to add an whole ListView for one row, similar to what is suggested by jewelsea here: JavaFX table- how to add components?

Of course I used a ListView instead of a Button. But then the TableView only presents the first entry of the ListView. Here my code for the Callback class:

public class IeListViewCallback implements
        Callback<TableColumn<ConnectedIEList, ConnectedIEList>, TableCell<ConnectedIEList, ConnectedIEList>> {
    @Override
    public TableCell<ConnectedIEList, ConnectedIEList> call(TableColumn<ConnectedIEList, ConnectedIEList> param) {
        return new TableCell<ConnectedIEList, ConnectedIEList>() {
            final ListView<String> listView = new ListView<String>();
            {
                listView.getItems().add("entry 1");
                listView.getItems().add("entry 2");
                listView.getItems().add("entry 3");
            }

            @Override
            public void updateItem(final ConnectedIEList connectedIEList, boolean empty) {
                super.updateItem(connectedIEList, empty);
                setGraphic(listView);
            }
        };
    }
}

Of course this code was only for testing. Usually the entries would depend on the commited List instead of being hard coded!

Community
  • 1
  • 1
deetz
  • 491
  • 1
  • 7
  • 20

1 Answers1

2

You can achieve this by explicitly setting the height of the sub-column to zero through css:

column.setStyle("-fx-pref-height: 0;")

You have to do this to all sub-columns of a column to see the effect.

Itai
  • 6,641
  • 6
  • 27
  • 51
  • Thank you very much! I Can't believe i didn't found this very easy method myself. I spend hours trying all kinds of different solutions. – deetz Jan 08 '16 at 14:34