JTable columnName not visible

Hii Javaites

I am creating JTable in the following way

private DefaultTableModel model = new DefaultTableModel();

model.addColumn("Name");

model.addColumn("Date");

model.insertRow(0, new Object[]{"Smith","18/05/06"});

JTable table = new JTable(model);

I am getting the JTable displayed minus the column Name i,e "Name" and "Date".

Can anyone tell me wht is wrong here

[423 byte] By [help_eachothera] at [2007-10-2 20:25:48]
# 1
http://onesearch.sun.com/search/onesearch/index.jsp?qt=jtable+no+header&subCat=siteforumid%3Ajava57&site=dev&dftab=siteforumid%3Ajava57&chooseCat=javaall&col=developer-forums
JayDSa at 2007-7-13 23:08:45 > top of Java-index,Desktop,Core GUI APIs...
# 2
For displaying column headers is it necessry to add JTable in a JScrollPane ?
help_eachothera at 2007-7-13 23:08:45 > top of Java-index,Desktop,Core GUI APIs...
# 3
C in your code u didn't created JScrollPane. If u create table simply on panel then u can only get data rows. To get columns + rows u must first create object of Scroll Pane and then add jTable to the scroll pane.This is sure u will get the desired results.
Vikranta at 2007-7-13 23:08:46 > top of Java-index,Desktop,Core GUI APIs...
# 4

Yes i did not created table on JScrollPane.

I am creating a JPanel(MainPanel) , which consists of two more JPanels (addPanel and diplayPanel )

I am creating a JTable in diplayPanel .

But as u said tht i should create a table in JScrollPanel.

I did that and added that ScrollPanel to my JPanel (MainPanel)

But in this way i am getting a line visible i.e No rows and no columns are visible.

So can u plz tell me what went wrong ?

Can we add a JScrollPane to a JPanel ?

help_eachothera at 2007-7-13 23:08:46 > top of Java-index,Desktop,Core GUI APIs...