aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Adjusting the Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adjusting the "clickable" area of JButton" Watch "Adjusting the "clickable" area of JButton" New topic
Author

Adjusting the "clickable" area of JButton

R. Ramage
Greenhorn

Joined: Aug 10, 2011
Posts: 13
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]

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4527
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
R. Ramage
Greenhorn

Joined: Aug 10, 2011
Posts: 13
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]

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
might work like this, unless you want the text sideways as well

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4527
    
    5

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
 
subject: Adjusting the "clickable" area of JButton