Search code examples
javaswtjfacercp

How to set initial size of JFace Dialog?


I know that we can use getInitialSize() to set the initial size of a JFace Dialog.

The issue is that I have 2 monitors with different resolution (one is 2k monitor and another is 4k monitor which has high resolution).

I want to set size of a dialog in such a way that dialog should visible identically when I see in both the monitors. Basically I want to scale up my dialog to be visible properly in 4k monitor. How do I do this.


Solution

  • Though I was not able to find the exact solution, I found a workaround for by using org.eclipse.jface.layout.PixelConverter.

    Example :

    PixelConverter pc = new PixelConverter(control);
    pc.convertWidthInCharsToPixels(number);
    

    or

    PixelConverter pc = new PixelConverter(control);
    pc.convertHorizontalDLUsToPixels(number);
    

    Set the above code to GridData.widthHint or GridData.heightHint