• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Adjusting the "clickable" area of JButton

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm working on a project that we need some vertical buttons. I can render the button so that it looks how it should, but as far as catching mouse events it's still in the area that the button would normally occupy.

Any way to rotate the whole button instead of just the image or change the clickable area?

Code for the button currently:
Screen-Shot-2012-10-26-at-11.30.04-AM.png
[Thumbnail for Screen-Shot-2012-10-26-at-11.30.04-AM.png]
screenshot of the button
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At a glance, I'd guess you also need to override getPreferred/Maximum/MinimumSize, getSize, getBounds (and any similar methods I may have missed). An easy way would be to transpose and return the Dimension returned by the super implementation. e.g.
 
R. Ramage
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply Darryl. I took what you suggested and it inverted my problem. The clickable area is now where I want it but because the buttons dimensions have changed, the drawing goes back to looking horizontally [attached image]
Additional code:


The other size methods didn't seem to change it any. What you suggested got me thinking though that maybe I should just change the dimensions of the button and figure out how to rotate the associated text. Might be simpler than rotating the whole button. So again thank you for your time and input on this.
Screen-Shot-2012-10-26-at-3.08.31-PM.png
[Thumbnail for Screen-Shot-2012-10-26-at-3.08.31-PM.png]
Button w/ size overrides
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
might work like this, unless you want the text sideways as well

 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here are some old posts of mine on similarhttps://forums.oracle.com/forums/thread.jspa?messageID=5735198� topics. Note that not one of them is a fully tested, complete implementation, and that I was less than a year into Java and fairly new to Swing at the time.

I think the best approach is to write a custom ButtonUI that extends the corresponding UI class of the LaF used, as in the first posted link, but as a public class rounded off to provide the functionality needed to be able to set it as the default UI via UIManager.

https://forums.oracle.com/forums/thread.jspa?messageID=5737741�
https://forums.oracle.com/forums/thread.jspa?messageID=5747973�
https://forums.oracle.com/forums/thread.jspa?messageID=5761557�
https://forums.oracle.com/forums/thread.jspa?messageID=5735198�
https://forums.oracle.com/forums/thread.jspa?messageID=4938538�
https://forums.oracle.com/forums/thread.jspa?messageID=4938447�
 
reply
    Bookmark Topic Watch Topic
  • New Topic