B4J Tutorial How to change location to Msgbox2Async and other customizations

change location
You will surely have noticed that xui.Msgbox2Async places the alert in the center of the last form shown that depends on its Owner.

Sometimes there is a need to place it on a specific point on the screen. How to do?

B4X:
Dim msg As JavaObject = xui.Msgbox2Async("Message", "Title", "Yes", "", "No", Null)
Dim jo As JavaObject = Me
jo.RunMethod("PosDialog",Array (msg,300,300))
Wait For (msg) Msgbox_Result (Result As Int)
' ....................
#if Java
 import javafx.scene.control.Dialog;
 import javafx.scene.control.Alert;
// import javafx.scene.control.ButtonType;
// import javafx.scene.control.ButtonBar;
 
   public static void PosDialog(Alert alrt, int x, int y) {
    alrt.setX(x);
    alrt.setY(y);
   System.out.println("work fine");
 }
#End If
 
Last edited:

Star-Dust

Expert
Licensed User
MsgBox without buttons
A few weeks ago I read a post where it was asked how to get a MsgBox without buttons by closing it by code.
I immediately felt it was useless, because any ProgressDialog can be used very well for the same purpose.
But the question technically intrigued me as it faces some problems that are insurmountable at first sight. So after an hour of reflection I found the solution, now after weeks I want to share the solution

The problem that seemed insurmountable was that the Alert window closes only with the click event on the Button. This does not happen if there is no button, not even if you click on the X of the window. The Close method of the Alert/Dialog does not give any result.
So I thought about inserting the Cancel button when needed, when the code is requested to close. And I wanted to do it so that it would not be seen .... here is the solution:
B4X:
Sub Button1_Click
    'xui.MsgboxAsync("Hello World!", "B4X")
    Dim D As JavaObject = xui.Msgbox2Async("Message","Title","","","",Null) ' No button

    Sleep(4000)
    Dim fu As JavaObject = Me
    fu.RunMethod("addclose",Array (D)) ' Add button
    fu.RunMethod("closedialog",Array (D)) ' Close
End Sub


#if Java
 import javafx.scene.control.Dialog;
 import javafx.scene.control.Alert;
 import javafx.scene.control.ButtonType;
 import javafx.scene.control.ButtonBar;
 
 public static void addclose(Alert alrt) {
    alrt.getButtonTypes().clear();
    alrt.getButtonTypes().add(new ButtonType(" ", ButtonBar.ButtonData.YES));

    //This message causes the views to drop down and the close button does not appear in the dialog box
    alrt.setHeaderText("Close by code");
 }
 
 public static void closedialog(Dialog<?> d) {
    d.close();
    System.out.println("done");
  }

#End If
 
Last edited:
Top