views:

181

answers:

3

Hi guys, I'm working on rotating a loaded image. I set the graphics on a JPanel and then use standard AffineTransform in order to rotate it, say, 45 degrees. Unfortunately, the image is being cut, if it exceeds the panel area. How may I force JPanel to add scrolls to itself (while loading an image file, I would like to adjust the size of JPanel by adding the scrolls, without adjusting the size of JFrame).

Or, in other words, how to correctly rotate the whole image?

Thank you in advance for the reply!

+1  A: 

Use a JScrollPane instead.

Tedil
+1  A: 

You need to put the panel in a jscrollPane and then make sure you have the preferredsize set correctly so that the scroll will be available.

broschb
A: 

Well, I would suggest that you should not be rotating the image in the paintComponent() method of your panel since this will result in the preferred size of the panel changing and you should not be setting the preferred size in the paintComponent() method.

Instead you should probably have a rotate(...) method. This method will create a BufferedImage of the desired rotation. Then your paintComponent() method simply paints the buffered image. Then you would set the preferred size based on the rotation.

Now regarding the preferred size of the rotated image check out this example.

camickr