I would like to display files and folders in a TreeViewer with the associated Windows shell icons. I use the SHGetFileInfo function to get the icons, and then I convert them to org.eclipse.swt.graphics.Image.

It works great, but when I display a large number of files I get an error: "org.eclipse.swt.SWTError: No more handles". SWT is right, I created too many images. Because I must return them from org.eclipse.jface.viewers.LabelProvider.getImage(Object).

How should I handle this situation?

(I can't "cache" the images, because the icons can be dynamic, and even different for every folder.)

有帮助吗?

解决方案

You do need to work out a way to identify the different unique images you get from SHGetFileInfo and only create one Image for each. You must also keep track of the images you create because you must also dispose of them.

You may be able to use org.eclipse.jface.resource.ImageRegistry to help manage the images. This requires a string key to identify each image. It looks like SHGetFileInfo gives you an index number that could be used as a unique key.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top