B4J Question MainForm.SetFormStyle("UTILITY") crashes my File open dialog

Scantech

Well-Known Member
Licensed User
Longtime User
B4X:
MainForm.SetFormStyle("UTILITY")
I wanted to find a way to disable those minimize, maximize and close button. I prefer UTILITY over Undecorative.

B4X:
Private Sub btnLoadFile_Click
    firmware = Array As Byte() ' Resets to an empty array (length 0)
    jframe.InitializeNewInstance("javax.swing.JFrame",Array(""))
    openFileDialog
End Sub
Private Sub openFileDialog
    Dim fileChooser As JavaObject
    fileChooser.InitializeNewInstance("javax.swing.JFileChooser", Array(Null))
    Dim result As Int = fileChooser.RunMethod("showOpenDialog", Array(jframe))
    If result = fileChooser.GetField("APPROVE_OPTION") Then
        Dim selectedFile As JavaObject = fileChooser.RunMethod("getSelectedFile", Null)
        Dim filePath As String = selectedFile.RunMethod("getPath", Null)
        LogMessage("Status", "Selected file Path: " & filePath)
        Dim FileName As String = fileChooser.RunMethodJO("getSelectedFile",Null).RunMethod("getName",Null)
        LogMessage("Status", $"Selected file name: ${FileName}"$)
        ' Process and convert to binary the selected file
        firmware = ConvertHexIntelToBinaryRange(filePath, START_ADDR_FLASH)
    Else
        LogMessage("Status", "No file selected.")
    End If
   
    ' Must do or app will not exit. Caused by fileChooser
    If jframe.IsInitialized Then
        jframe.RunMethod("dispose", Null)
    End If
End Sub
File Chooser works great without setting a formstyle. However, in UTILITY i select file and click OPEN in dialog then it crashes with no error log. Debug is still running.

Can we make this code work in UTILITY Style?
 

Scantech

Well-Known Member
Licensed User
Longtime User
I just realize we have Filechooser option (not java objects). It works with any form style.
 
Upvote 1
Top