Search code examples
javajavafxjavafx-8scenebuilder

Making a column in a TableView not visible until requested


I've used javaFX's scenebuilder to create a TableView. Let's say there a 10 columns. Some of those columns will probably not be relevant to most users so, I would like to hide them at start-up. The user could reveal the other columns as needed. What code can I put in the FXMLController that would hide those columns at start-up? If they were hidden at start-up would they still be visible in the tableMenuButton?

(I am using JavaFX 8)


Solution

  • All column defined in the fxml will be automatically added in the menuButtons list, just the same as if they were defined in code. To show the menuButton of the table, set its attribute

    <TableView fx:id="tableView" tableMenuButtonVisible = "true">
    

    To control the visibility state of a column, set its visible attribute (nothing special compared to other attributes :)

    <TableColumn text="Artist" visible="false">