0

I'm experiencing a problem with AWT in rotating the graphics in a panel by 90 degrees. I can rotate the graphics in a panel by casting to Graphics2D and applying a transform. The problem with this is that if the panel area is rectangular then part of the graphics becomes hidden. I can't seem to set clip bounds to the whole area. If, for example, the window is short and wide then the clip region becomes narrow and tall. If the window is narrow and tall the clip region becomes short and wide. I don't know how to override this behavior.

Is there a better way of doing this or a way to work around the problem?

EDIT SOLVED:- It turns out that overriding behavior of getWidth() and getHeight() is a bad idea lol

  • 1
    For better help sooner, post an [SSCCE](http://sscce.org/). – Andrew Thompson Sep 19 '13 at 15:04
  • In your [sscce](http://sscce.org/), access posted images via `URL`, as shown [here](http://stackoverflow.com/a/10862262/230513); use synthetic images as shown [here](http://stackoverflow.com/a/15982915/230513); or use `UIManager` icons, as shown [here](http://stackoverflow.com/a/12228640/230513). – trashgod Sep 19 '13 at 15:59

1 Answers1

2

As shown here, override getPreferredSize() on the enclosing panel to return a Dimension that can accommodate your desired view, e.g. Math.max(width, length). As shown here,

  • Translate the image to the origin.

  • Rotate the image.

  • Translate the image back to the center of the panel.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045