Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to chnage the angle of a button ?  RSS feed

 
Avin Sinanan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello does anyone out there know how to change the angle of a JButton from horizontalto lets say at an angle of 45 degress or even 55 degrees or even how to rotate a JButton?
yours respecfully Avin Sinanan
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Man... this was a pretty fun class to make work...

Here's your angled button and a fun little test class to show the full range of this buttons movement...



Have Fun!

-Nate
[ March 25, 2002: Message edited by: Nathan Pruett ]
 
Thomas Smets
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Natan,
I have been tru' you code of the AngledButton & I have been quiet impressed because I don't understand exactly what you are doing with it.
More specifally what you do there in the paint & paint Border methods

Could you give some more hints on why you are calculating these points & what they are for ?
I am also very much puzzled by the need to do the clipping & the need to redraw the old version of the Button !
Would it be possible to have a few indication on they needs & they reasons ?
Thomas SMETS,
SCJP2 - Brussels
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to remember my code from March...

I believe the problem is this... when you rotate the button at an angle, the button still has the same "size", so, you only get the rotated button drawn in the area that the non-rotated button would occupy. If you change the size of the displayed area, you are changing the size of the button, so I had to figure out some way to draw the button using the super.getPreferredSize(), but display the button in an area large enough the show all of the rotated button. That is accomplished through the overridden paint() method. The paintBorder() method also had to be messed with because the border is drawn based on the size.

Hopefully this answers your question... if not, I can take a more in depth look at the code and help out some more...

-Nate
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!