B4J Question [SOLVED] Please advise on alternative code that works with jdk11?

Mashiane

Expert
Licensed User
Longtime User
Ola

B4X:
Sub GetFileIcon(Dir As String, FileName As String) As Image
    Dim jo As JavaObject
    Dim JavaFile As JavaObject
    Dim icon As JavaObject
    JavaFile.InitializeNewInstance("java.io.File", Array(File.Combine(Dir, FileName)))
    If GetSystemProperty("os.name", "").ToLowerCase.Contains("win") Then
        icon  = jo.InitializeStatic("sun.awt.shell.ShellFolder").RunMethodJO("getShellFolder", Array(JavaFile)).RunMethod("getIcon", Array(True))
    Else
        icon = jo.InitializeStatic("sun.awt.shell.ShellFolder").RunMethodJO( _
        "getShellFolder", Array(JavaFile)).RunMethod("getIcon", Array(True))
        Dim fc As JavaObject
        fc.InitializeNewInstance("javax.swing.JFileChooser", Null)
   
        Dim icon As JavaObject = fc.RunMethodJO("getUI", Null).RunMethodJO("getFileView", Array(fc)).RunMethod("getIcon", Array(JavaFile))
        Dim AquaIcon As JavaObject
        AquaIcon.InitializeStatic("com.apple.laf.AquaIcon")
        icon = AquaIcon.RunMethod("getImageForIcon", Array(icon))
    End If
    Return AwtImageToImage(icon)
End Sub

Private Sub AwtImageToImage(img As JavaObject) As Image
    Log(GetType(img))
    Dim jo As JavaObject
    Return jo.InitializeStatic("javafx.embed.swing.SwingFXUtils").RunMethod("toFXImage", Array(img, Null))
End Sub

I am getting an error on the AwtImageToImage sub. with normal java this works.

Thanks.
 

Star-Dust

Expert
Licensed User
Longtime User
 
Upvote 1
Solution

Star-Dust

Expert
Licensed User
Longtime User
Sorry, i have a headache i can't help you, but you can just use #IF JAVA
 
Upvote 0
Top