SWT已经 封装了Win32的ImageList对象,而Table的小图标也是通过ImageList实现的。
看一下Table中创建小图标的代码,就可以验证这一点
int imageIndex (Image image) {
if (image == null) return OS.I_IMAGENONE;
if (imageList == null) {
Rectangle bounds = image.getBounds ();
imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height);
int index = imageList.indexOf (image);
if (index == -1) index = imageList.add (image);
int hImageList = imageList.getHandle ();
/*
* Bug in Windows. Making any change to an item that
* changes the item height of a table while the table
* is scrolled can cause the lines to draw incorrectly.
* This happens even when the lines are not currently
* visible and are shown afterwards. The fix is to
* save the top index, scroll to the top of the table
* and then restore the original top index.
*/
int topIndex = getTopIndex ();
if (topIndex != 0) {
setRedraw (false);
setTopIndex (0);
}
OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, hImageList);
if (headerImageList != null) {
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
int hHeaderImageList = headerImageList.getHandle ();
OS.SendMessage (hwndHeader, OS.HDM_SETIMAGELIST, 0, hHeaderImageList);
}
fixCheckboxImageList (false);
if (itemHeight != -1) setItemHeight (false);
if (topIndex != 0) {
setTopIndex (topIndex);
setRedraw (true);
}
return index;
}
int index = imageList.indexOf (image);
if (index != -1) return index;
return imageList.add (image);
}
如果想实现大图标,可以写一个类继承Tabel,要和Table放在一个包中,然后实现创建大图标的代码就可以了。