Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

Can Components be Rotated Visually?

Thread view: 
larkmore@aol.com - 18 May 2007 21:54 GMT
This has come up a lot recently.  Is there a way to apply a rotation
to how a component is displayed?  I'm not referring to things covered
by SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.  What I want
to do is take a JLabel and rotate the entire thing counterclockwise by
ninety degrees so it reads along the side of the screen, or flip a
JProgressBar so it "grows" from top to bottom instead of bottom to
top.  Is there a way to do this with predefined components?
-Will
Tom Hawtin - 18 May 2007 22:24 GMT
> This has come up a lot recently.  Is there a way to apply a rotation
> to how a component is displayed?  I'm not referring to things covered
[quoted text clipped - 3 lines]
> JProgressBar so it "grows" from top to bottom instead of bottom to
> top.  Is there a way to do this with predefined components?

You can rotate the Graphics object passed through paint. Unfortunately
it becomes more complicated if you include events (like repaint events),
and the whole component tree and co-ordinate thing is exposed and all
incestuous.

Tom Hawtin
larkmore@aol.com - 21 May 2007 13:17 GMT
Sounds ugly, but how exactly would one do that?  I skimmed the API
documentation for the Graphics class and didn't see anything about
rotating.
-Will

> larkm...@aol.com wrote:
> > This has come up a lot recently.  Is there a way to apply a rotation
[quoted text clipped - 11 lines]
>
> Tom Hawtin
Tom Hawtin - 21 May 2007 22:22 GMT
> Sounds ugly, but how exactly would one do that?  I skimmed the API
> documentation for the Graphics class and didn't see anything about
> rotating.

It's the Graphics2D features you want.

Tom Hawtin
larkmore@aol.com - 22 May 2007 14:13 GMT
> It's the Graphics2D features you want.
>
> Tom Hawtin

I'm still confused on how to do this.  How do I convert a Graphics
object into a Graphics2D object so I can apply the rotation?  If I
wait until the paint(Graphics g) method to be called, the Graphics
object is already instantiated and I see no way to cast it or convert
it into a Graphics2D object.
-Will
Lew - 22 May 2007 14:38 GMT
>> It's the Graphics2D features you want.
>>
[quoted text clipped - 5 lines]
> object is already instantiated and I see no way to cast it or convert
> it into a Graphics2D object.

Graphics2D g2 = (Graphics2D) g;

You'll be wanting to read
<http://java.sun.com/docs/books/tutorial/2d/index.html>

Signature

Lew

Tom Hawtin - 22 May 2007 15:21 GMT
> I'm still confused on how to do this.  How do I convert a Graphics
> object into a Graphics2D object so I can apply the rotation?  If I
> wait until the paint(Graphics g) method to be called, the Graphics
> object is already instantiated and I see no way to cast it or convert
> it into a Graphics2D object.

The Graphics object you get from paint will be a Graphics2D object. You
just need to cast it to get the more specific static type.

Tom Hawtin


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.