Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JTable columns title text with vertical orientation

691 views
Skip to first unread message

Werner Nussbaumer

unread,
Jun 5, 2003, 4:52:46 AM6/5/03
to
Hi all

How can I change the title text of jTable columns to a vertical
orientation (rotate for example 90 degrees)?

Thanks for any help,
regards
Werner Nussbaumer

Daniel Dyer

unread,
Jun 5, 2003, 5:55:17 AM6/5/03
to
On 5 Jun 2003 01:52:46 -0700, Werner Nussbaumer <w.nuss...@datacomm.ch>
wrote:

You need to write a custom TableCellRenderer that draws its text vertically
and set that as the renderer for the JTableHeader on the table.

--
Daniel Dyer
Empathy Software (http://www.empathysoftware.com)

Werner Nussbaumer

unread,
Jun 5, 2003, 9:13:02 AM6/5/03
to
Daniel Dyer <dan....@dontspammeempathysoftware.com> wrote in message news:<oprqagifegiihdmk@localhost>...

> On 5 Jun 2003 01:52:46 -0700, Werner Nussbaumer <w.nuss...@datacomm.ch>
> wrote:
>
> > Hi all
> >
> > How can I change the title text of jTable columns to a vertical
> > orientation (rotate for example 90 degrees)?
> >
> > Thanks for any help,
> > regards
> > Werner Nussbaumer
>
> You need to write a custom TableCellRenderer that draws its text vertically
> and set that as the renderer for the JTableHeader on the table.

Thanks. I used:

class CustomTableHeaderCellRenderer extends DefaultTableCellRenderer
{
public Component getTableCellRendererComponent(JTable table, Object
value, boolean isSelected, boolean hasFocus, int row, int column)
{
Component cell = super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, column);
cell.setFont(new Font("SansSerif",Font.PLAIN,10));
cell.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
setOpaque(true);
return this;
}
}

But ComponentOrientation has no property for rotating the text.

Do you have an example on how to rotate the text?

Thanks a lot,
regards
Werner Nussbaumer

Daniel Dyer

unread,
Jun 5, 2003, 10:06:00 AM6/5/03
to
On 5 Jun 2003 06:13:02 -0700, Werner Nussbaumer <w.nuss...@datacomm.ch>
wrote:

Sorry I only gave you half an answer, unfortunately I'm not sure about
rotating the text, I've not needed to do it before. Is there maybe some
way to apply a translation to the text before painting it (worst case is
that you could over-ride paint component and paint the text yourself)?

Werner Nussbaumer

unread,
Jun 6, 2003, 3:09:02 AM6/6/03
to

However this works, I don't know, and that's why I asked the
specialists of this newgroup.

Any idea?
Regards
Werner Nussbaumer

0 new messages