We have the problem that rich dialogs runs in screens with different screen resolutions. Running always in full screen mode is no solution and with modal dialogs even not possible. To avoid the scroll bars that some users have, we would like to set the window size depending from the resolution so that everybody gets the best window size.

I know I can get the screen size with java.awt.Toolkit.getDefaultToolkit().getScreenSize(). But if use this value in panel.preferredSize it does not work properly.

The logic of Rich dialogs is executed on the server. It means that when you execute your code, then the screen size of the server is returned and set to the preferred size. For sure the screen size on the client will be different and the result is not good.

You can use the ClientContext class to get the screen size of the client, but this class is only available when the first rich dialog is started. Another workaround is that window sizes are stored for every user. So, after the user changes the window size after the first start of the rich dialog, the next time the window will open in that size. Note, that this works only for logged in users.