How to javafx hide table background header?

I am trying to automatically develop a full text that shows a drop-down list of sentences in a tableview popup, and I have a question, how can I hide the whole column of a tableview header in javafx 2.1

+4
javafx tableview
source share
3 answers

Apply the customs table to the table:

table.getStylesheets().addAll(getClass().getResource("hidden-tableview-headers.css").toExternalForm()); 

If the hidden-tableview-headers.css located in the same place as the class loading the css resource and containing the line:

 .column-header-background { visibility: hidden; -fx-padding: -1em; } 

The visibility: hidden attribute tells JavaFX not to draw a node, but to leave the field in which the header was. Since the title is 1 line high by the height of the text, you can tell the invisible title not to take up space by setting -fx-padding: -1em; .

+13
source share

The solution is very simple; after rendering the tableview, we can get the table title and make it invisible, so the table title should not be re-arranged when changing the layout of the table. To handle the rendering of the table, we can use the change to the width property and hide the table title

Here is the code:

 tableView.widthProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) { // Get the table header Pane header = (Pane)tableView.lookup("TableHeaderRow"); if(header!=null && header.isVisible()) { header.setMaxHeight(0); header.setMinHeight(0); header.setPrefHeight(0); header.setVisible(false); header.setManaged(false); } } }); 
+5
source share

If you do not want to add an additional .css file, you can use the existing css:

 .hide-header .column-header-background { visibility: hidden; -fx-padding: -1em; } 

Where .hide-header is a random name that you should add to your java code:

 table.getStyleClass().add("hide-header"); 
0
source share

All Articles