Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JTable column header not visible

Tags:

java

swing

column header not visible in my JTable i have created a JPanel and added the JTable to the JPanel.

Object rowData[][] = { { "Row1-Column1", "Row1-Column2", "Row1-Column3"},                 { "Row2-Column1", "Row2-Column2", "Row2-Column3"} };             Object columnNames[] = { "Column One", "Column Two", "Column Three"};             JTable jTable = new JTable(rowData, columnNames);  
like image 413
Lalchand Avatar asked May 18 '11 15:05

Lalchand


People also ask

How to show header in JTable?

The DefaultTableCellRenderer class can extend JLabel class and it can be used to add images, colored text and etc. inside the JTable cell. We can hide the table header of a JTable by unchecking the JCheckBox and show the table header of a JTable by clicking the JCheckBox.


1 Answers

The API for JTable states:

"Note that if you wish to use a JTable in a standalone view (outside of a JScrollPane) and want the header displayed, you can get it using getTableHeader() and display it separately."

Or just add the table to a scrollpane, and add your scrollpane to the panel...

like image 193
Amir Afghani Avatar answered Sep 23 '22 17:09

Amir Afghani