• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to create jtable with rowheader as well as with columnheader

 
santosh kimothi
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to create a table where i want to display header in front of each row as well as header above of all column......

i tried many example but i am not getting any code with both column header as well as row header......

some examples are having row header but not having column header.........some are having column header but not having row header..

can anybody help me how to make jtable with row and column header.......please reply,,,,,
 
Rob Camick
Ranch Hand
Posts: 2599
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well a column header is created automatically when you add a JTable to a JScrollPane, so I don't understand your problem with that.

> some examples are having row header

So then use that example to add the row header.

If you need further help then you need to create a SSCCE (Short, Self Contained, Compilable and Executable, Example Program), that demonstrates the incorrect behaviour.

Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.
 
Maneesh Godbole
Saloon Keeper
Posts: 11064
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like Rob said, it is difficult without seeing any code.
I take it you know how to create and use tables. If not you might find this useful http://java.sun.com/docs/books/tutorial/uiswing/components/table.html Notice the section about adding tables to a containers. That might be one of the reasons why you are not seeing the column header.
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved this once by simply adding a column at the start of my TableModel, then giving that column a special TableCellRenderer which mimics the look&feel of the table header, and adding a mouse listener to the table to handle clicks on that column.
 
Brian Cole
Author
Ranch Hand
Posts: 907
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:I solved this once by simply adding a column at the start of my TableModel, then giving that column a special TableCellRenderer which mimics the look&feel of the table header, and adding a mouse listener to the table to handle clicks on that column.


The feature that this approach lacks is to have the row header not scroll with the rest of the table. Or rather, to scroll up/down with the table but to stay put when scrolling left/right.

For that, typically a one-column table is added to the west side of table's scroll pane via JScrollPane.setRowHeader(). This is reasonably simple so long as the rows of the main table are all the same height.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic