Set default font for SWT Shell

我的未来我决定 提交于 2020-07-20 09:33:33

问题


Is there a way to set a default font for the whole Shell such that any new control will use that same font?

It seems that right now I have to set the font for every control I create, which leads to too much redundancy.


回答1:


Font which is used by default is chosen by platform (see other info in Class Font - SWT: The Standard Widget Toolkit), so it's not possible to set default font for all widgets, if you want that, you have to do it "by hand"..

Why are you changing default font anyway..?




回答2:


There was not an api to change the default font size.

However, we could use class shadowing side effect to do that. For example (osx), duplicated a source code org.eclipse.swt.internal.cocoa.NSFont and update the method

public static NSFont systemFontOfSize(double fontSize) {
    // hacking it by class shadowing
    fontSize = 24;
    long result = OS.objc_msgSend(OS.class_NSFont, OS.sel_systemFontOfSize_, fontSize);
    return result != 0 ? new NSFont(result) : null;
}

We re-assign a bigger font size before SWT get the result

It is hacking, not recommended using at the production evnironment.



来源:https://stackoverflow.com/questions/7220643/set-default-font-for-swt-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!