Enlarge clickable area of button [closed]

2019-09-20 12:01发布

I have a Java applet which is running on a touchscreen monitor. I want to activate e.g. a button's action even when the user didn't hit it exactly. Maybe in a range of 5 pixel of the click, the nearest clickable object have to trigger his action.

How do I enlarge a button's hit area?

For example, if the size of a button is (width=100, height=25), the clickable area of this button should be a little bit larger than the button itself (width=120, height=45)

What I´m looking for is like TouchDelegate class from Android... ...Helper class to handle situations where you want a view to have a larger touch area than its actual view bounds...

1条回答
虎瘦雄心在
2楼-- · 2019-09-20 12:50

There is padding option for this purpose.
So if you use padding your button looks smaller than the actual clickable area.

Sorry I don't know how to set it in Java applet. Try this post, I suppose Insets correspond to padding OR try this (like stated here):

button.setMargin(new Insets(10,10,10,10));

Edit
If you can use drawable resource to serve in place of a button there is another way - just make border transparent.

查看更多
登录 后发表回答