File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding JTableHeader

 
tadi raja
Ranch Hand
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to center alignment of rotated text of JTableHeader in JTable ??
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by tadi raja:
How to center alignment of rotated text of JTableHeader in JTable ??


What do you mean by "rotated text" ?
 
tadi raja
Ranch Hand
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
perhaps also the call to super... might be responsible for the lines
 
tadi raja
Ranch Hand
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic