简体   繁体   English

SWT:不再有控制手柄

[英]SWT: No more Control handles

Using eclipse, I have created a Form Editor with 2 tabs for my application. 使用eclipse,我为我的应用程序创建了一个带有2个选项卡的表单编辑器。 One tab is for GUI support and the other one is for normal text editor. 一个选项卡用于GUI支持,另一个选项卡用于常规文本编辑器。 In the GUI page, I have been using hundreds of SWT controls such as tables, sections, buttons, etc. 在GUI页面中,我一直在使用数百个SWT控件,例如表,节,按钮等。

The problem is when I opened more than 20 files with the Form Editor in my application, I get an exception "SWT: No more handles". 问题是,当我在应用程序中使用“表单编辑器”打开20多个文件时,出现异常“ SWT:没有更多的句柄”。 I could understand that there is no more control handles for the controls to be created to the Form Editor. 我可以理解,没有更多的控件句柄可用于创建到表单编辑器的控件。 I could check the control handles availability and proceed to open the file, if enough handles are available. 如果有足够的句柄,我可以检查控件句柄的可用性并继续打开文件。 Otherwise i can not open the file itself. 否则我无法打开文件本身。

Is there any possible way to solve this problem? 有什么办法可以解决这个问题?

You may well have reached the limit. 您可能已经达到极限。 Note that the number of handles varies a lot between platforms (macOS, Linux, Windows) so if you plan to run this on different platforms you need to test on all of them. 请注意,不同平台(macOS,Linux,Windows)之间的句柄数量差异很大,因此,如果计划在不同的平台上运行它,则需要在所有平台上进行测试。

If you are using SWT classes derived from Resource ( Color , Font , Image , Cursor , ....) then you must call dispose on the object when you are done with it. 如果您使用的是从Resource派生的SWT类( ColorFontImageCursor ,....),则在dispose完该对象后必须调用dispose Failing to do so will leak handles. 否则会泄漏手柄。

You should also try to share these resources - for example don't create a new Color each time. 您还应该尝试共享这些资源-例如,不要每次都创建新的Color Use a manager class that handles sharing the colors, the manager class can also handle disposing of the resources. 使用管理器类处理共享的颜色,管理器类也可以处理资源的处置。

JFace provides manager classes such as ColorRegistry , FontRegistry and ImageRegistry which might be useful. JFace提供了可能有用的管理器类,例如ColorRegistryFontRegistryImageRegistry

If this is not enough you will have reduce this large number of controls, perhaps you could use pop-up dialogs to show some of the information when buttons are pressed. 如果这还不够,您将减少大量控件,也许您可​​以使用弹出对话框在按下按钮时显示一些信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM