Based on @Erel's code here....
xui.MsgboxAsync & xui.Msgbox2Async don't have a "cancel" method, so trying to use it generates an error: java.lang.RuntimeException: Method: cancel not found in: javafx.scene.control.Alert
Instead, the 'close' or 'hide' methods can be used:
Notes:
1. Both these methods return an xui.DialogResponse_Cancel result.
2. I think that using the information linked below someone who understands JavaObject better than I do might be able to set the result to xui.DialogResponse_Positive or xui.DialogResponse_Negative using the setResult method before closing the dialog. I'd be interested to see the code to do that if anyone wants to post it here.
ref. https://openjfx.io/javadoc/17/javafx.controls/javafx/scene/control/Alert.html
xui.MsgboxAsync & xui.Msgbox2Async don't have a "cancel" method, so trying to use it generates an error: java.lang.RuntimeException: Method: cancel not found in: javafx.scene.control.Alert
Instead, the 'close' or 'hide' methods can be used:
B4X:
Sub Globals
Dim Dialog As JavaObject
End Sub
Sub OpenMsgbox
Dialog = xui.Msgbox2Async("Question?", "Title", "Yes", "Cancel", "No", Null)
CloseAfter5Seconds
Wait For Msgbox_Result (Result As Int)
Dialog = Null
If Result = xui.DialogResponse_POSITIVE Then
Log("yes")
Else If Result = xui.DialogResponse_Cancel Then
Log("cancel")
Else If Result = xui.DialogResponse_Negative Then
Log("no")
End If
End Sub
Sub CloseAfter5Seconds
Sleep(5000)
If Dialog.IsInitialized Then
' Dialog.RunMethod("hide", Null)
Dialog.RunMethod("close", Null)
End If
End Sub
Notes:
1. Both these methods return an xui.DialogResponse_Cancel result.
2. I think that using the information linked below someone who understands JavaObject better than I do might be able to set the result to xui.DialogResponse_Positive or xui.DialogResponse_Negative using the setResult method before closing the dialog. I'd be interested to see the code to do that if anyone wants to post it here.
ref. https://openjfx.io/javadoc/17/javafx.controls/javafx/scene/control/Alert.html
Last edited: