Dynamically set position of modal

I’d like to set the position of a modal dialog dynamically to the position of the item click event.
I get the x and y position from click event. In descriptor I can set x and y position of the dialog, but how can I do it dynamically in the event?

@Subscribe("myGrid")
protected void onMyGridClick(final DataGrid.ItemClickEvent<Customer> anEvent)
{
    final int xPos = anEvent.getClientX();
    final int yPos = anEvent.getClientY();
    
    screenBuilders.editor(Customer.class, this)
                    .withOpenMode(OpenMode.DIALOG)
                    .withAfterCloseListener(e -> myGridRefresh.actionPerform(myGrid))
                    .build()
                    .show();
}

Hello,

to set position of dialog you should get DialogWindow instance from your screen. Try the following code:

@Subscribe("myGrid")
protected void onMyGridClick(final DataGrid.ItemClickEvent<Customer> anEvent)
{
    final int xPos = anEvent.getClientX();
    final int yPos = anEvent.getClientY();

    Screen screen = screenBuilders.editor(Customer.class, this)
            .withOpenMode(OpenMode.DIALOG)
            .withAfterCloseListener(e -> myGridRefresh.actionPerform(myGrid))
            .build();

    DialogWindow dialogWindow = (DialogWindow) screen.getWindow();
    dialogWindow.setPosition(xPos, yPos);

    screen.show();
}
1 Like