B4J Question JavaFX Scene Builder use own controls

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi All,

I have defined an own control NumberTextField, build a class accordingly to then use it in the FXML file.
Question: How to include the generated class in the FXML file? What path needs to defined? Where to place the class?

FXML file: What path to set?
B4X:
<?import NumberTextField?>

FXML File: Here is how the new control is included:
B4X:
<NumberTextField id="textfieldMinPerKm2" layoutX="100.0" layoutY="178.0" prefWidth="138.0" promptText="Min per Km" />

The Java Class
B4X:
package com.rwblinn;

import javafx.scene.control.TextField;

public class NumberTextField extends TextField {
   
    @Override public void replaceText(int start, int end, String text) {
          if (text.matches("[0-9]") || text == "") {
              super.replaceText(start, end, text);
          }
      }
   
      @Override public void replaceSelection(String text) {
          if (text.matches("[0-9]") || text == "") {
              super.replaceSelection(text);
          }
      }
}
 

rwblinn

Well-Known Member
Licensed User
Longtime User
You will need to create a library and add it to the IDE.
Hi Erel,

  1. defined the library (jar & xml). Packagename = rljfxml with class NumberTextField.
  2. copied the rljutilsjar and xml to the b4j lib folder
  3. added to the fxml file the import statement: <?import rljfxml.*?>
  4. added to the fxml file the control <NumberTextField id="textfieldMinPerKm" layoutX="100.0" layoutY="178.0" prefWidth="138.0" promptText="Min per Km" />
  5. during compile receive error:
    Program started.
    main._appstart (java line: 106)
    javafx.fxml.LoadException: NumberTextField is not a valid type.
    at javafx.fxml.FXMLLoader.createElement(FXMLLoader.java:2415)
    at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2345)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2164)
    at anywheresoftware.b4j.objects.PaneWrapper.LoadLayout(PaneWrapper.java:120)
    at com.rwblinn.roavgsplit.main._appstart(main.java:106)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
    at com.rwblinn.roavgsplit.main.start(main.java:32)
    at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
    at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:216)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
    at java.lang.Thread.run(Thread.java:744)
  6. Pls find project (roavgsplit) and lib (rljfxml) attached.

 

Attachments

  • roavgsplit.zip
    4.4 KB · Views: 266
  • RLJFXML.ZIP
    6.7 KB · Views: 282
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

thanks for the replies so far. Slowly progressing:
Step 1
Custom Control defined as a library (see attached rljfxml folder). The custom control is also shown in the javafx scene builder.
The library files (jar and xml - generated using b4a doclet) also copied to the b4j library folder.

Step 2
Use the custom control in b4j (see attached rljfxmlex folder). During loading of the library an error occured, like ... numbertextfield.maxwidth... already exists. Based on this info, have checked the xml file generated by the b4a doclet. the xml contains duplicate names for the same method and property.
Example for maxwidth:

B4X:
<method> <name>maxWidth</name>
<method><name>maxWidthProperty</name>
<property><name>MaxWidth</name>


Stripping out the duplicates, resolved the problem and the library can be loaded.

Any hints appreciated on how to create an xml file that can be loaded into b4j?
I used bj4 beta 6.
 

Attachments

  • rljfxml.zip
    13.9 KB · Views: 293
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi Erel,

will try to convert for textview.
Quick Q: where to find this import and which library to add to eclipse:
import anywheresoftware.b4j.objects.PaneWrapper.NativeAndWrapper;
 
Upvote 0
Top