Can Components be Rotated Visually?

Discussion in 'Java' started by larkmore@aol.com, May 18, 2007.

  1. Guest

    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
     
    , May 18, 2007
    #1
    1. Advertising

  2. Tom Hawtin Guest

    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
     
    Tom Hawtin, May 18, 2007
    #2
    1. Advertising

  3. Guest

    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 <> wrote:
    > 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
     
    , May 21, 2007
    #3
  4. Tom Hawtin Guest

    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
     
    Tom Hawtin, May 21, 2007
    #4
  5. Guest

    On May 21, 5:22 pm, Tom Hawtin <> 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
     
    , May 22, 2007
    #5
  6. Lew Guest

    wrote:
    > On May 21, 5:22 pm, Tom Hawtin <> 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
     
    Lew, May 22, 2007
    #6
  7. Tom Hawtin Guest

    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
     
    Tom Hawtin, May 22, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jae

    Rotated text in a datagrid

    Jae, Nov 21, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    1,441
    vMike
    Nov 22, 2003
  2. Mickey Segal
    Replies:
    0
    Views:
    897
    Mickey Segal
    Feb 2, 2004
  3. Petr Aubrecht

    reload rotated image

    Petr Aubrecht, May 6, 2005, in forum: Java
    Replies:
    3
    Views:
    432
    Roland
    May 9, 2005
  4. david wolf
    Replies:
    1
    Views:
    421
    java-john
    Mar 23, 2006
  5. msorion
    Replies:
    5
    Views:
    2,827
    Jacqui or (maybe) Pete
    Jul 22, 2003
Loading...

Share This Page