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

Rotating the JLabel

Thomas Smets
Ranch Hand

Joined: Dec 11, 2001
Posts: 111
On another site forum, I met the question about rotating a JLabel & pretended I would answer the question. so here is what I wrote :
Giving you the answer for the JLabel may not be a good idea but ... that's what you asked for !
Firstly then, why is it a good idea :
With a normal Swing Component you would have to provide him a Renderer & that would do. I mean you just need to chuck a look at the various example on the internet where you could create you CustomCellRendere for a JTable ....
Back to our problem !
In the case of the JLabel, it has a very different story because the JLabel is really a different animal !
You will have to create you own class RotatableJLable extending the JLabel (There is really no other way, I think) ...
What do you have to implement in the Subclass to do the job is the method :
paintComponent (Graphics g)

I then proposed the following code but it doesn't work ... though I was pretty confident it should work :

Can someone help me to express / find why it doesn't work ?
[ June 02, 2002: Message edited by: Thomas SMETS ]

Thomas Smets
Just another developper
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Because you were posting on another site.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Nathan Pruett devised an AngledButton that extends JButton a while back. I'd bet it could be adapted to work as a JLabel.
Good Luck.
I agree. Here's the link:
subject: Rotating the JLabel
jQuery in Action, 3rd edition