This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable help needed.  RSS feed

 
Kamlesh Sangani
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I m using JTable to dsisplay data. I m extending AbstractTableModel.
But I dont know how to set columnheading n data in table?
In class i m declaring 2D array for column headnings. but which method i should call to make these headning appear on JTable?
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to override "String getColumnName (int column)" in your implementation of the table model to return the correct column name. As AbstractTableModel does not do any data or header storage, you need to know where the headers are and return them appropriately from this method.
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And it just occurred to me that you need to wrap the jTable into a JScrollPane to view the heading, so if jt is the handle to your JTable object and jp is the JPanel on which you want to place it, use:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!