我正在使用一个 swt 对话框,如果我将字体大小(控制面板 -> 显示)从小(100%)增加到大(150%),控件就会从屏幕上被切断 这可以使用
来解决对于第2点,我无法获取当前的Windows大小。如果我明白了,问题就可以解决,因为可滚动复合材料不适合较小的尺寸。
我是按照以下方式做到的:
Display.getCurrent().getDPI().x
这里根据返回值(96、120或144)可以分别判断尺寸是100%、125%还是150%
我知道这是一个老话题,但它仍然是一个实际问题,答案是不适用于 Windows 10,当使用多个显示器时,每个屏幕上的比例可能不同。 SWT 仅考虑一台具有全分辨率的显示器,返回的 DPI 将是默认屏幕之一。
我分享我使用 AWT API 找到的解决方案,因为 SWT 没有帮助:
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;
...
}
}
}
您可以对每个监视器使用 widget.getMonitor().getZoom() 。