gpt4 book ai didi

java - SWT (JFace) 中的 FontRegistry 和 Dispose

转载 作者:行者123 更新时间:2023-11-30 02:22:48 31 4
gpt4 key购买 nike

我正在学习如何使用 FontRegistry 及其工作原理。目前我有一个集中类(FontUtils),它在启动时加载所有字体数据,如下所示:

fontRegistry.put("small",new FontData[]{new FontData("Tahoma",8, SWT.BOLD)});

稍后在我的程序中我使用这个:

gc.setFont(FontUtils.getFont("small"));

我想知道是否必须处置在 FontUtils 中创建的字体,因为根据文档,每次创建字体时都应该处置它。但 FontRegistry 对字体的创建一无所知,实际上它没有名为 dispose 的方法。我必须自己处理垃圾吗?

例如,使用一个变量来计算有多少资源正在使用该字体,如果为 0,则处理该字体?

因为我要对 ImageRegistry 执行相同的操作,所以我认为行为是相同的,对吧?

最佳答案

FontRegistry 管理它拥有的所有字体并处理它们的处置。

JavaDoc 说:

A font registry owns all of the font objects registered with it, and automatically disposes of them when the SWT Display that creates the fonts is disposed. Because of this, clients do not need to (indeed, must not attempt to) dispose of font objects themselves.

这是使用 DisplaydisposeExec 方法完成的。

ImageRegistry 是相同的:

An image registry owns all of the image objects registered with it, and automatically disposes of them when the SWT Display that creates the images is disposed. Because of this, clients do not need to (indeed, must not attempt to) dispose of these images themselves.

如果您想提前处理图像,

ImageRegistry 也有一个 dispose 方法。

注意:可以使用您自己的 ResourceManager 创建 ImageRegistry,在这种情况下,由资源管理器来安排处置。

关于java - SWT (JFace) 中的 FontRegistry 和 Dispose,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46388925/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com