This week's book giveaway is in the Kotlin forum.We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# How to chnage the angle of a button ?

Avin Sinanan
Ranch Hand
Posts: 109
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
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
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
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