B4J Tutorial JavaFX17+ InlineUris

JavaFX17 added the possibility to use inlineURIs. One use for this is to add small CSS Stylesheets from code:

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
 
    MainForm.Stylesheets.Add(GetDataURI(StyleSheet))

End Sub

Private Sub StyleSheet As String
    Return $"
.button{
    -fx-background-color:green;
}"$
End Sub

Private Sub GetDataURI(Data As String) As String
    Dim SU As StringUtils
    Return "data:text/css;base64," & SU.EncodeBase64(Data.GetBytes("UTF-8"))
End Sub

1754836265134.png

Simple to use and very useful for libraries where you would otherwise need to add a stylesheet to the Files directory.

DependsOn :
  • JavaFX 17+
  • jStringUtils (Internal library)
 
Last edited:

Magma

Expert
Licensed User
Longtime User
When listening "java" i am trying to hide... because i am afraiding it.. but now i am curious... all javafx 17 goodies are possible with Android native (b4a) ?... with the same way ? or i must keep hiding...

is there a way to use it somehow... (i know that the real answer is no - but i hope for a trick)
 
Top