B4J Question Why is Button key press sensitive ?

Starchild

Active Member
Licensed User
I have a B4J program with a button added using Designer.
The button just has the text label "+"

When I run the program and press the SPACE key, the CLICK event for this button is executed.

How do I remove the keyboard sensitivity from this button.

I have NOT assign a key listener to the button.
Looking online I see the object InputMap for jButtons, and
an InputMap has a Clear function.

I tried writing this function.

B4X:
Public Sub ClearButtonKeypresses(ThisButton As Button)
    Private nativeMe As JavaObject=Me
    nativeMe.RunMethod("clearButtonInputMap",Array(ThisButton))
End Sub


#if JAVA
import javax.swing.InputMap;
import javax.swing.JButton;

public void clearButtonInputMap(JButton button) throws Exception 
{
    InputMap inputMap = button.getInputMap();
    inputMap.clear();
}
#end if

When I pass the B4j Button to the Java code I get...

java.lang.RuntimeException: Method: clearButtonInputMap not matched.

I would welcome any helps resolving this, or
another method of clearing any associated keys from a button.
 

Cableguy

Expert
Licensed User
Any node that has focus will trigger either with space key, enter key and some will also capture pageup/down and backspace.

In the click event you will need to try to find how this event was triggered
 
Last edited:
Upvote 0

Daestrum

Well-Known Member
Licensed User
Use the MouseClicked event
B4X:
Sub yourButton_MouseClicked (EventData As MouseEvent)
…
Then it wont trigger on anything other than a mouse click on the button.

(Also a Button in a B4J UI program is not a jButton)
 
Upvote 0
Top