• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

how to create jtable with rowheader as well as with columnheader

 
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,,,,,
 
Rancher
Posts: 3204
29
  • 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.
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • 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.
 
Sheriff
Posts: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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.
 
Author
Posts: 974
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.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic