How do I create a JTable that does not display a table header?

Jon Wingfield

There are a number of ways to do this.

The simplest is just not to use a JScrollPane container for the JTable. Whenever a JTable is added to a container the protected JTable method configureEnclosingScrollPane() is called. This tries to set the JTableHeader to be the columnHeaderView for the enclosing scrollpane.

If you require the table to be in a scrollpane then sub-class JScrollPane so that it does not display a columnHeaderView by overriding setColumnHeaderView(...) to do nothing:


JTable table = new JTable();
JScrollPane scroller = 
    new JScrollPane(table) {
        public void setColumnHeaderView(Component view) {}
    };

See also "How to use Tables" (http://java.sun.com/docs/books/tutorial/uiswing/components/table.html) in The Java Tutorial at Sun for more details.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact