• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

How to chnage the angle of a button ?

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic