Hide or disable close icon in pages

I need to hide or disable the close icon shown in the below popup. How to do that.
I was not able to find any line regarding that in the screen
jmix query 1

Hello!

You can hide this “close” icon using custom styles. Firstly, you should you get Window object of the opened screen. For instance, for InputDialog:

InputDialog dialog = dialogs.createInputDialog(this)
         // ...
        .build();

JmixWindow jmixDialog = (JmixWindow) ((Component.Wrapper) dialog.getWindow()).getComposition();
jmixDialog.addStyleName("custom-dialog");

dialog.show();

And styles:

.custom-dialog .v-window-closebox {
  display: none;
}

@pinyazhin
Its not actually a dialog it is a screen opened as dialog with setting below

The screen is opened using below code
screenBuilders.screen(this)
.withScreenClass(Chooseclient.class)
.withAfterCloseListener(e → {

            })
            .build()
            .show();

And ChooseClient has its own ChooseClient.xml

InputDialog is a general example, you can do the same with your screen:

Chooseclient screen = screenBuilders.screen(this)
        .withScreenClass(Chooseclient.class)
        .withOpenMode(OpenMode.DIALOG)
        .withAfterCloseListener(e -> {
        }).build();
JmixWindow screenDialog = (JmixWindow) ((Component.Wrapper) screen.getWindow()).getComposition();
jmixDialog.addStyleName("custom-dialog");
screen.show();

Or if Chooseclient always opened as a dialog, you can place this code to the InitEvent of Chooseclient:

@Subscribe
public void onInit(InitEvent initEvent) {
    Window window = getWindow();
    if (window instanceof DialogWindowImpl) {
        ((DialogWindowImpl) window).getComposition().addStyleName("custom-dialog");
    }
}

Hi @kiran.ouseph

I think there is another option which also prevent the close of the dialog (screen) by keyboard shortcut (ESC) and doesn’t need the usage of an additional style to hide the close button ( X ).

    @Subscribe("testBtn")
    public void onTestBtnClick(Button.ClickEvent event) {
        WebviewScreen screen = screenBuilders.screen(this)
                .withScreenClass(WebviewScreen.class)
                .withOpenMode(OpenMode.DIALOG)
                .withAfterCloseListener(e -> {
                }).build();
        Window window = screen.getWindow();
        if (window.isCloseable())
            window.setCloseable(false);
        screen.show();
    }

the additional check ‘window.isClosable()’ is optional since you open the dialog/screen definitely in dialog mode.

If you like the second option from @pinyazhin with the InitEvent, you can use the ‘setClosable(false)’ also there.

If you had already defined in the descriptor of your dialog/screen the dialogMode for dialog size or position, you can add the attribut closeable="false" there and you don’t need to add any code in the controller.

BR
Stefan

1 Like

@stefan.kraus Thanks It worked