问题
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