When i create a JTable like the code shown below:

[B]String[] columnNames = {"First Name",
                                "Last Name",
                                "Sport",
                                "# of Years"};

        Object[][] data = {
            {"", "",
              new Integer(5),""},
            {"", "",
              new Integer(5),""},
            {"", "",
              new Integer(5),""},
{"", "",
              new Integer(5),""},
           {"", "",
              new Integer(5),""},
        };
 

     	JTable table=new JTable(data,columnNames);
	table.doLayout() ;[/B]

jp2.add(table);//where jp2 is a panel on a container on a frame

I dont get the Column names of the TABLE ..
The Table Screenshot i m presenting in the attachments

Please Help me with how to get Column names Displayed in the Table when the program is run

Attachments have screenshots of program when run..

Please post whole code

This line from the JTable API explains your issue

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.

. You probably want a scroll pane anyway if the number of rows can exceed your view area.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.