Reputation: 71
I am using an swt dialog in which the controls get cut off from the screen if I increase the font size(Control Panel-> Display) from smaller(100%) to large(150%) This can be solved using
For point 2, I am unable to get the current Windows size. If I get that, the problem can be solved as the scrollable composite isn't suitable for the smaller size.
Upvotes: 4
Views: 2090
Reputation: 1
I know it is an old subject, but it still is an actual problem, and the answer is not working with windows 10, where the ratio can be different on each screen when using several displays. SWT only consider one Display with the full resolution, and DPI returned will be the one of the default screen.
I share the solution I found using AWT API, as SWT won't help:
import java.awt.*;
...
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
// find the screen on which we draw
for (GraphicsDevice gd : gds){
DisplayMode dm = gd.getDisplayMode();
for (GraphicsConfiguration gc : gcs) {
Rectangle bnds = gc.getBounds();
if (bnds.contains(pt)){
// pt is a java.awt.Point in the working area in virtual coordinates
// and here is the expected windows ratio
int ratio = 100 * dm.getWidth() / bnds.width;
...
}
}
}
Upvotes: 0
Reputation: 71
I did it in the following way:
Display.getCurrent().getDPI().x
Here, based on the return value(96, 120 or 144) it can be determined if the size is 100%, 125% or 150% respectively
Upvotes: 3