Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Hide / Remove TableView headers

892432Dec 9 2011 — edited Oct 23 2013
Is there a way to hide or remove just the table headers from a tableView? I've tried setting nulls to header text but that just affected the header label.

Thanks,
Denis

Comments

jsmith Dec 11 2011
Perhaps not the best way to do it, but the following code worked for me if executed after show was called on the stage containing the table.
Pane header = (Pane) table.lookup("TableHeaderRow");
header.setVisible(false);
table.setLayoutY(-header.getHeight());
table.autosize();
892432 Dec 12 2011 — edited on Dec 12 2011
Thanks for that lookup ID, that's what I needed.

I did the following, and it worked:
list.widthProperty().addListener(new ChangeListener<Number>()
        {
            @Override
            public void changed(ObservableValue<? extends Number> source, Number oldWidth, Number newWidth)
            {
                ...other stuff...
                
                //Don't show header
                Pane header = (Pane) list.lookup("TableHeaderRow");
                if (header.isVisible()){
                    header.setMaxHeight(0);
                    header.setMinHeight(0);
                    header.setPrefHeight(0);
                    header.setVisible(false);
                }
            }
        });
The resize happens on .show() and so I don't have to worry about when my table is being built.

Is there a "OnShow" event, because that would be a better place for this code... but this works.

Edited by: denis77 on Dec 12, 2011 7:45 AM
User_CDX3F Oct 23 2013

I've a nested column, i.e. one column has 2 columns in it. How to disable only the header of the sub column and not the main column's header.

Example:

TableColumn main = new TableColumn("");

TableColumn lastName = new TableColumn("Last Name");

TableColumn firstName = new TableColumn("First Name");

main.getColumns().addAll(lastName , firstName );

When this is rendered, it displays 1 main header and 2 sub header Last Name and First Name. Now how to only hide showing of First and Last Name column's header.

Is it possible?

Thanks.

1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Nov 20 2013
Added on Dec 9 2011
3 comments
23,085 views