Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it possible to give row names and column names for a JTable

 
sum prit
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir, i have a little bit of idea about JTable. I do not know whether it is possible to give both the row names and column names in a JTable. I have seen some examples by googling and everywhere i found that while displaying data only column names are given.

I have a database with a table having Temperature, Rainfall and DateTime columns. Now my requirement is to give Temperature, Rainfall name as rows and DateTime a columns and corresponding to a particular DateTime i need to display Temperature and Rainfall values. Is it possible to give?

please provide me some suggestion so that i can continue further.

Thank you in advance. Any help from you will highly be appreciated......
 
Rob Camick
Ranch Hand
Posts: 2539
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually it the JScrollPane that supports both a column header and a row header.

A JTable takes advantage of this by creating a column header component. A JTable does not support a row header component.

So you will need to create a custom row header component. This component could actually be a JTable. The Row Number Table is an example of such a component. It obviously doesn't do what you want it do to, but it should help you in creating your own component.
 
sum prit
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Sir for giving me a way to continue. Now i will try something to do and proceed further.....

Thank you once again for your immense help..
 
Hernan Acosta
Greenhorn
Posts: 7
Hibernate MySQL Database Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use a second table with one column for the row header, and use it like a fixed column. You also can render it with a header kind Look & Feel .

To create columns that don't scroll (the row header), you need to place a second table in the row header view of the JScrollPane. Then when the user scrolls the table vertically, the two tables will remain in sync.
The two tables then need to share their ListSelection Model. That way, when a row in one table is selected, the row in the other table will automatically be selected.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic