问题
I am working under eclipse plugin and trying to load fonts into the application as resources, so they will appear in project explorer tree.
In SWT we have method loadFont of Display class which loads font from specified file, so it will appear in list of available fonts of application. I am using this method.
But when I am trying to delete the font from project explorer I am getting following exception:
org.eclipse.core.internal.resources.ResourceException: Problems encountered while deleting resources
I have following questions:
- Is it possible to unload font from application in SWT ?
- Is there any way to deal with it?
- Is there another scenario to deal with custom fonts in eclipse?
回答1:
Classes of the type FontData don't need to be disposed of, as they simply contain a small amount of information about the font. When you create an actual Font object then yes, it is your responsibility to call .dispose() and free up those resources.
If you are using JFace as well as SWT, then you may want to look at FontRegistry, which assists in keeping track of font resources.
Apologies for not linking any javadocs, the SWT docs aren't loading for me right now. I did find a small example of FontRegistry usage which explains the difference between FontData and Font.
来源:https://stackoverflow.com/questions/4898904/uninstall-fonts-installed-using-swts-display-loadfont-api