开发者

Set default font for SWT Shell

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

It s开发者_开发知识库eems that right now I have to set the font for every control I create, which leads to too much redundancy.


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..?


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

Set default font for SWT Shell

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜