user465001
user465001

Reputation: 846

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)

Upvotes: 1

Views: 553

Answers (2)

user465001
user465001

Reputation: 846

I've come up with the code below and, it. I'm still looking for a way to it without loops.

for (Object col : playListTableView.getColumns()) {
    TableColumn colCasted = ((TableColumn)col);
    if(colCasted.getText().equals("Artist")){
        colCasted.setVisible(false);
    }
}

Upvotes: 0

kleopatra
kleopatra

Reputation: 51535

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">

Upvotes: 1

Related Questions