B4J Question JavaFX Custom Control Access Methods

Similar threads

B4J Tutorial Raspberry Pi with Java 11
B4J Library jGoogleMaps library
B4J Code Snippet [tool] ScenicView
B4J Tutorial Working with JavaFX Scene Builder
B4J Library [class] CSS Utils
B4J Library ControlsFX Library

rwblinn

Well-Known Member
Licensed User
Hi,

developed (in java) my first working [not easy must say = sweat]) JavaFX Custom Control TextFieldNowWidget: An Anchorpane with a Label, TextField and Button (to set the actual date + time in the TextField). Methods defined are setLabel(String s), getText, getVersion.
1) Exported the Custom Control TextFieldNowWidget to a jar and copied to the B4J external libraries folder.
2) Build a B4J wrapper jTextFieldNowWidget for this Custom Control and copied to the B4J external libraries folder.
3) created a sample app in B4J using TextFieldNowWidget (added as additional jar) and jTextFieldNowWidget (added as a Lib).
To access TextFieldNowWidget in B4J, defined:
B4X:
Sub Process_Globals
   Private textfieldnowwidget1 As Node
...

'Get the text from the inputfield
'Not found a way yet to directly access the methods by using textfieldnowwidget1.method, like textfieldnowwidget1.getText
Sub btnGetText_Action
   Dim jo As JavaObject = textfieldnowwidget1
   lblGetText.Text = jo.RunMethod("getText", Null)
   'JUST for a Test Log(jo.RunMethod("getVersion", Null))
End Sub
Question
Instead of using a JavaObject to access the TextFieldNow methods, like getText is there a way to use textfieldnowwidget1.getText?
What do I need to change in the Wrapper?

Pls find code attached.
 

Attachments

rwblinn

Well-Known Member
Licensed User
Hi Erel,

one jar is used for the JavaFX Scenebuilder (imported as Custom Control) and java apps using that custom control.
the other is a B4J wrapper (jar + xml) using that library (referenced in the eclipse project). The B4J wrapper shows only the standard node methods, but not the ones defined in the wrapper.
Something I do wrong or miss to include only the Custom Control methods. But do not know how to resolve?
 

Erel

Administrator
Staff member
Licensed User
This code is taken from WebViewWrapper:
B4X:
static {
     //This line ties the native WebView with this wrapper. It is required for the integration with Scene Builder (FXML layouts).
     PaneWrapper.nativeToWrapper.addFirst(new NativeAndWrapper(WebView.class, WebViewWrapper.class));
   }
You need to add a similar static constructor to your class if you want that your class will be instantiated during the layout building process.

The following method will be called:
B4X:
@Override
   @Hide
   public void innerInitialize(final BA ba, final String eventName, boolean keepOldObject) {
     if (!keepOldObject)
       setObject(new WebView());
     super.innerInitialize(ba, eventName, true);
     if (ba.subExists(eventName + "_locationchanged")) {
       getObject().getEngine().locationProperty().addListener(new ChangeListener<String>() {

         @Override
         public void changed(ObservableValue<? extends String> arg0,
             String arg1, String arg2) {
           ba.raiseEventFromUI(getObject(), eventName + "_locationchanged", arg2);
         }
       });
     }
     if (ba.subExists(eventName + "_pagefinished")) {
       getObject().getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {

         @Override
         public void changed(ObservableValue<? extends State> arg0,
             State arg1, State arg2) {
           if (arg2 == State.SUCCEEDED) {
             ba.raiseEventFromUI(getObject(), eventName + "_pagefinished", getObject().getEngine().getLocation());
           }
         }
       });
     }
   }
 

rwblinn

Well-Known Member
Licensed User
Thanks for feedback.

Explored further on how to create JavaFX Custom Controls and use these in B4J - afterall not that difficult.

For those interrested, two comprehensive JavaFX Custom Control examples (using Eclipse & B4J) developed while learning:
TextFieldClear with B4J Wrapper: here
TextFieldNow with B4J Wrapper: here
 
Top