This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

AffineTransform, getRotateInstance and JPanel  RSS feed

 
Fernando Sanz
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I want to rotate by 90 degrees the JPanel that contains my GUI.
So far I have seen that using getRotateInstance (from AffineTransform), Strings and other components can be rotated.
But I haven't been able to understand how to rotate the whole GUI (or the JPanel, with everything it contains).
Could anybody tell me where I could find an example? or explain how I can rotate a JPanel?
Thanks
Fernando
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could override the paint() method to paint everthing to another image instead of directly to the component, then rotate the image and paint the image to the component. However, there are other things to keep in mind...

Unless the component is perfectly square and rotations are done in 90 degree increments, you're going to run into problems with the size, preferred size, etc. of the component. You can't just override the getPreferredSize(), getSize() etc. methods to return the size changed to rotation. These values are reported to both the component that contains the rotated component, and to the components inside the rotated component. For rotation to work, you want the components inside to ignore the size changed due to rotation, and for components that hold the rotated component to acknowledge size changed due to rotation.

Also, the image of the component will rotate, but what about things that can be selected in the component like buttons, textfields, etc.? Their image will appear rotated, but they cannot be clicked on or selected because the are not actually at the location they appear to be. You'd have to click on where the un-rotated button would be to click on it.
 
Fernando Sanz
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nathan,
it sounds like quite a difficult task for the moment.
Cheers
Fernando
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!