File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes regarding JTableHeader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "regarding JTableHeader" Watch "regarding JTableHeader" New topic
Author

regarding JTableHeader

tadi raja
Ranch Hand

Joined: Jul 07, 2008
Posts: 109
How to center alignment of rotated text of JTableHeader in JTable ??
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10170
    
    8

Originally posted by tadi raja:
How to center alignment of rotated text of JTableHeader in JTable ??


What do you mean by "rotated text" ?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
tadi raja
Ranch Hand

Joined: Jul 07, 2008
Posts: 109
Rotated Text means the text rotated at an angle of 90 degrees and that text should be center of JTableHeader in JTable.

thank you in advance.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10170
    
    8

How are you rotating the text? By tweaking paint?
You will have to use the FontMetrics to figure out the dimensions of the rendered font and then tweak the g.drawString()'s 'x' and 'y' co-ordinates accordingly.

Just out of curiosity, what exactly are you trying to do here by rotating the text?
tadi raja
Ranch Hand

Joined: Jul 07, 2008
Posts: 109
Here is the code for how to rotate the text..



and i am using following code to rotate the text.

table.getTableHeader().getColumnModel().getColumn(0).setHeaderRenderer(new RotatedTableCellRenderer(270));

the above code turns the text 270 degrees and the text is always align to right side and how to make it as center alingment.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10170
    
    8

Originally posted by tadi raja:


the above code turns the text 270 degrees and the text is always align to right side and how to make it as center alingment.


Rotating 270 degrees means making it upside down. So your left becomes your right and you are setting it at 0,0.

Like I said before, you need to use the FontMetrics and adjust your 0,0 accordingly.
Also check out
This is a nice article which uses text rotation for getting Adobe style tabbed pane tabs.
tadi raja
Ranch Hand

Joined: Jul 07, 2008
Posts: 109
That code works fine and i aligned at center when i was change that line of code to g2.drawString(this.getText(), 8, -52); but here one problem is that the rotated text added to JTableHeader,i was unable get both horizontal lines and vertical lines, it can applied for row data only not for the JTableHeader.

table.setShowGrid(false);
table.setShowHorizontalLines(true);
table.setShowVerticalLines(true);
table.setGridColor(Color.black);

the above code applicable for only row data not for the JTableHeader.

can you please give me any suggestions regarding this issue

thank you in advance.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10170
    
    8

I am a bit confused now.

Ok. Initially you had a problem in aligning text on the table headers. Now you are saying it is fixed and you are satisfied with the alignment.

Now you have a new problem that the table grid (both horizontal and vertical lines as you call it) is not visible.

Is my understanding correct?
tadi raja
Ranch Hand

Joined: Jul 07, 2008
Posts: 109
yes you are correct,i am unable to get horizontal or vertical lines in JTableHeader even if i added the following lines

table.setShowGrid(false);
table.setShowHorizontalLines(true);
table.setShowVerticalLines(true);
table.setGridColor(Color.black);

thank you in advance..
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10170
    
    8

By default, the grid is visible. So take out all your grid related calls.

If it still doesnt work, post your SSCCE code so we can take a look.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Try setting a BevelBorder(BevelBorder.RAISED) to your renderer.

And for the rotated text, override paintComponent. Not paint.

db
[ October 15, 2008: Message edited by: Darryl Burke ]

luck, db
There are no new questions, but there may be new answers.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
perhaps also the call to super... might be responsible for the lines
tadi raja
Ranch Hand

Joined: Jul 07, 2008
Posts: 109
Hi Darryl Burke,

Thank you for your reply.

I am trying to set the border as BevelBorder.RAISED to renderer component, it is not setting properly.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regarding JTableHeader
 
Similar Threads
Look and Feel
Stopping of Table Columns Moving
Help on JTable
Columns in JTable
regarding JTableHeader