Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Can Components be Rotated Visually?

Reply
Thread Tools

Can Components be Rotated Visually?

 
 
larkmore@aol.com
Guest
Posts: n/a
 
      05-18-2007
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

 
Reply With Quote
 
 
 
 
Tom Hawtin
Guest
Posts: n/a
 
      05-18-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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?


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
 
Reply With Quote
 
 
 
 
larkmore@aol.com
Guest
Posts: n/a
 
      05-21-2007
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

On May 18, 5:24 pm, Tom Hawtin <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > 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?

>
> 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



 
Reply With Quote
 
Tom Hawtin
Guest
Posts: n/a
 
      05-21-2007
(E-Mail Removed) wrote:
> 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
 
Reply With Quote
 
larkmore@aol.com
Guest
Posts: n/a
 
      05-22-2007
On May 21, 5:22 pm, Tom Hawtin <(E-Mail Removed)> wrote:
> 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

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      05-22-2007
(E-Mail Removed) wrote:
> On May 21, 5:22 pm, Tom Hawtin <(E-Mail Removed)> wrote:
>> 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.


Graphics2D g2 = (Graphics2D) g;

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

--
Lew
 
Reply With Quote
 
Tom Hawtin
Guest
Posts: n/a
 
      05-22-2007
(E-Mail Removed) wrote:
>
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reload rotated image Petr Aubrecht Java 3 05-09-2005 11:52 AM
SWING components adjustment in different resolutions - Should show scrollbars less than 800X600 and expand components over this resolution Bluetears76 Java 1 07-01-2004 09:01 PM
Can Choice components respond to keyboard input like HTML Choice components? Mickey Segal Java 0 02-02-2004 10:59 PM
Rotated text in a datagrid Jae ASP .Net 2 11-22-2003 01:03 AM
Text rotated 90 - deg. is it possible ? msorion HTML 5 07-22-2003 08:27 PM



Advertisments