B4J Question [SOLVED] How to use virtual keyboard?

techknight

Well-Known Member
Licensed User
Longtime User
So, I am trying to create a raspberry pi app which opens a standalone X11 session.

Trouble is, I cant get the virtual keyboard to pop up and be used. How do I do this?

From searching other areas of the forum, I currently have these in my AppStart subroutine:

Code:
    SetSystemProperty("com.sun.javafx.touch", "true")
    SetSystemProperty("com.sun.javafx.isEmbedded", "true")
    SetSystemProperty("com.sun.javafx.virtualKeyboard", "javafx")

But they are not working.

Also I am using Debug mode under B4J-Bridge to the R-Pi
 
Ok, well according to the internet I found something.

So, I am trying this:
Code:
Sub cmdTest_Click
    Dim NativeMe As JavaObject
    NativeMe.InitializeContext
    NativeMe.RunMethod("show", Array As Object(txtTeamNameHome))
'    MainForm.RootPane.MouseCursor = GetMouseCursor("NONE")

End Sub
#IF JAVA
    public void show(TextField textField) {
        textField.getProperties().put(FXVK.VK_TYPE_PROP_KEY, "numeric");
        FXVK.init(textField);
        FXVK.attach(textField);
    }
    public void hide() {
        FXVK.detach();
    }
#End If

Of course I get an error saying this:

src\md\sm1000\bs059rgbtnc\main.java:2354: error: cannot find symbol
public void show(TextField textField) {
^
symbol: class TextField
location: class main
1 error
 
Upvote 0
in the java add
after the #If Java line​
Code:
import javafx.scene.control.TextField;
 
Upvote 0
Tried it. Crashes at:
java.lang.NoSuchFieldException: sharedProcessBA

Which is the NativeMe.InitializeContext line.
 
Upvote 0
try
Code:
    Dim NativeMe As JavaObject = Me
    NativeMe.RunMethod("show", Array(txtTeamNameHome))
 
Upvote 0
Ugh. Yet another crash. I wish I knew Java but I dont...

Code:
Waiting for debugger to connect...
Program started.
BrightSet: 160
Error occurred on line: 185 (Main)
java.lang.IllegalArgumentException: object is not an instance of declaring class
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
    at md.sm1000.bs059rgbtnc.main._cmdtest_click(main.java:2273)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
    at anywheresoftware.b4a.shell.S
hell.raiseEventImpl(Shell.java:228)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.BA$1.run(BA.java:215)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
    at javafx.graphics/com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:92)
    at javafx.graphics/com.sun.glass
.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:51)
    at java.base/java.lang.Thread.run(Thread.java:844)
 
Upvote 0
Change the
Code:
public void show(…)
to
Code:
public static void show(…)


(same for hide too)
 
Upvote 0
Another internet post says it has to be done like this:

textField.getProperties().put("vkType", "numeric");

But I dont know how to dothat as there is no getproperties on a B4J textfield.
 
Upvote 0
Change the
Code:
public void show(…)
to
Code:
public static void show(…)


(same for hide too)

Tried it.

Code:
Waiting for debugger to connect...
Program started.
BrightSet: 160
Error occurred on line: 185 (Main)
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
    at md.sm1000.bs059rgbtnc.main._cmdtest_click(main.java:2273)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
  
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.BA$1.run(BA.java:215)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
    at javafx.graphics/com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:92)
    at javafx.graphics/com.sun.glass.ui.monocle.RunnableProcessor.run(Run
nableProcessor.java:51)
    at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.ClassCastException: java.base/java.lang.String cannot be cast to java.base/java.lang.Integer
    at javafx.controls/com.sun.javafx.scene.control.skin.FXVKSkin.getNodeVKType(FXVKSkin.java:357)
    at javafx.controls/com.sun.javafx.scene.control.skin.FXVKSkin.updateKeyboardType(FXVKSkin.java:370)
    at javafx.controls/com.sun.javafx.scene.control.skin.FXVKSkin.prerender(FXVKSkin.java:466)
    at javafx.controls/com.sun.javafx.scene.control.skin.FXVK.init(FXVK.java:93)
    at md.sm1000.bs059rgbtnc.main.show(main.java:2947)
    ... 26 more

Current code:
Code:
Sub cmdTest_Click
    Dim NativeMe As JavaObject = Me
    NativeMe.RunMethod("show", Array As Object(txtTeamNameHome))
'    MainForm.RootPane.MouseCursor = GetMouseCursor("NONE")
   
End Sub
#IF JAVA
    import javafx.scene.control.TextField;
    import com.sun.javafx.scene.control.skin.FXVK;
    public static void show(TextField textField) {
        textField.getProperties().put(FXVK.VK_TYPE_PROP_KEY, "numeric");
        FXVK.init(textField);
        FXVK.attach(textField);
    }
    public static void hide() {
        FXVK.detach();
    }
#End If
 
Last edited:
Upvote 0
Ok, Now, I just commented out the getproperties line and the keyboard is working.

However its only showing the characters and everything is transparent, so thats telling me its not loading its CSS for some reason.
 
Upvote 0
maybe
Code:
textField.getProperties().put("vkType", "numeric");
 
Upvote 0
what was the error ? was it same as last time ?
 
Upvote 0
Yes it was.

But now I got the keyboard to load and hide, but its just the black text for the keys only.

There is no background or anything, which is strange.
 
Upvote 0
Gets even more strange.

If I force javafx.userAgentStylesheetUrl to Caspian or Modena on the Raspberry Pi java commandline, the Virtual Keyboard loads perfectly. style and all

However on the PC, its the same deal. Only loads the key text.

If I leave that line undefined on the R-Pi, its same thing. text only.

I also have to start the app directly. I cant add the flags to the app itself, or the B4J bridge command line or it does the same thing, text only.
 
Upvote 0
Back
Top