aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Urgent: JTable Header position Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Urgent: JTable Header position" Watch "Urgent: JTable Header position" New topic
Author

Urgent: JTable Header position

raphael Bereh
Ranch Hand

Joined: Jan 15, 2002
Posts: 79
Hi all,
Here is my problem. When you write the following code :
MyTableModel mymodel = new MyTableModel();
JTable table = new JTable(mymodel);
JScrollPane scroll = new JScrollPane(table);
the scroll pane gets the table header (Table Column Model) add displays it automatically at the TOP of the scroll pane,orientation is TOP-LEFT --> TOP-RIGHT. This is fine for most cases were a JTable is used. But in some cases were for instance, you want to display data side by side (for comparison, etc ..) it would be usefull to change this default behavior so that the Table header is displayed as Row-Header (TOP-LEFT --> BOTTOM-LEFT) and create a header that will be displayed in the 'normal' place of the header.(The model should understand the new (row,column) requests).
Example :
Here is a Table :
<CODE>
_____________________________________________________
|Surname | First Name | DOB | etc. | ppp | ppp | ppp |
______________________________________________________
xxxx | xxxx | xxx | xxxx | xxx | xxx | xxx |
______________________________________________________
.............
______________________________________________________
xxxx | xxx | xxx | xxx | xxx | XX | XXx |
______________________________________________________
</CODE>
Now, supposing I want to display Parent and Child data , the table would look like :
<CODE>
<PRE>
_____________________________________
| Parent | Child |
_____________________________________
Surname | xxxx | xxxx
_____________________________________
First name | xxx | xxxxx
_____________________________________
DOB | xxx | xxxx
______________________________________
etc. | xx | xxx
_____________________________________
ppp | xxx | xxx
_____________________________________
ppp | xxx | xxx
_____________________________________
ppp | xxx | xxx
_____________________________________
</PRE>
</CODE>
I would like to use the same TableModel(it is still the same data).
My question is, How can I get the Table Header to display (as in the figure). I don't have a proble creating row-header Jtables. The only solution I have at the moment is trying to translation (row, column) between the 2 tables, but I don't think it is the best way !
Any ideas ?
Thanks.
[ September 25, 2003: Message edited by: raphael Bereh ]
[ September 25, 2003: Message edited by: raphael Bereh ]
Christ UBB s*** Just give us some nice HTML - (<PRE> ) . My Table looks nothing like one !
[ September 25, 2003: Message edited by: raphael Bereh ]

SCJP,SCJD,SCBCD
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8968
    
    9

This guy does incredible stuff with Swing: Swing Examples
Check out the Row Header example second from the bottom.


[How To Ask Questions On JavaRanch]
raphael Bereh
Ranch Hand

Joined: Jan 15, 2002
Posts: 79
Thanks,
Know that url pretty well. Nothing really like what I need to do there.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Please refrian from using the word URGENT in your post subject. We treat every post on Javaranch with equal importance and using such words will not help your questions get answered any quicker. It's a bit annoying...


GenRocket - Experts at Building Test Data
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Urgent: JTable Header position