B4J Question How do I get the icon image of a file based on its extension and save it?

EnriqueGonzalez

Expert
Licensed User
Longtime User
Hi!

I only found this way:

B4X:
    Dim jo As JavaObject
    jo.InitializeStatic("javax.swing.filechooser.FileSystemView")
   
    Dim joFile As JavaObject
    joFile.InitializeNewInstance("java.io.File",Array("pathToFileAndFile"))
   
    Dim joSwing As JavaObject
    joSwing.InitializeStatic("javafx.embed.swing.SwingFXUtils")
   
    Dim ic As JavaObject = jo.RunMethodjo("getFileSystemView",Null).RunMethodJO("getSystemIcon",Array(joFile))
    Dim im As Image = joSwing.RunMethod("toFXImage",Array(ic.RunMethod("getImage",Null),Null))
   
    ImageView1.SetImage(im)
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Have you tested this code on a Mac to make sure it works not only on a PC?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…