Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adjusting the "clickable" area of JButton

 
R. Ramage
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • 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
screenshot of the button
[Thumbnail for Screen Shot 2012-10-26 at 11.30.04 AM.png]
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Button w/ size overrides
[Thumbnail for Screen Shot 2012-10-26 at 3.08.31 PM.png]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
might work like this, unless you want the text sideways as well

 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • 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�
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic