• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable-Header to tables without using JTable on a Scroll Pane

 
Vani Shastri
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi eveybody,

I am working on swings and i am facing a problem wrt JTables.
1. How to set the individual column width while using JTabels?
2. The header(headings to the respective columns) appears only if JTable is used along with a scrollpane. Can it be done with JTable alone?

Please help me with respect to this.

thank you.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.getColumnModel().getColumn(2).setPreferredWidth(200);

2)
it would be an extremely limited JTable, without the scrollpane
 
Brian Mozhdehi
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the table header, if this is not going to use a JScrollPane, then you must explicitly add the table header to the JPanel. See the post http://forum.java.sun.com/thread.jspa?threadID=176015&messageID=548337

where they show the use as follows:

JPanel myPanel = new JPanel( new BorderLayout() );
myPanel.add( myTable.getTableHeader(), BorderLayout.NORTH );
myPanel.add( myTable, BorderLayout.CENTER );

where myTable is your JTable.

You can of course use any Layout Manager you like, such as GridBag, etc.
 
Vani Shastri
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. That was a needful help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!