2

好的,所以我创建了这样的图像:

Image deleteImage = new Image(viewer.getTable().getDisplay(),
                        Provider.PATH_TO_DELETE_ICON);

如何添加鼠标侦听器以便我知道何时单击图像?

这是我的标签提供程序类:

private class MyLabelProvider extends LabelProvider implements
            ITableLabelProvider {

        @Override
        public Image getColumnImage(Object element, int columnIndex) {
            if (columnIndex == 3) {
                Image deleteImage = new Image(viewer.getTable().getDisplay(),
                        Provider.PATH_TO_DELETE_ICON);
                return deleteImage;
            }
            if (columnIndex == 4) {
                Image editImage = new Image(viewer.getTable().getDisplay(),
                        Provider.PATH_TO_EDIT_ICON);
                return editImage;
            } else
                return null;
        }

        public String getColumnText(Object element, int index) {
            Provider provider = (Provider) element;
            switch (index) {
            case 0:
                return Integer.toString(provider.getId());
            case 1:
                return provider.getName();
            case 2:
                return provider.getBulstat();
            default:
                return "";
            }
        }

    }
4

1 回答 1

6

您可以创建一个Label,将您的图像设置在它上面

label.setImage(deleteImage)

之后,您可以执行以下操作:

label.addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent arg0) {
            System.out.println("Click");
        }

        @Override
        public void mouseDown(MouseEvent arg0) {

        }

        @Override
        public void mouseDoubleClick(MouseEvent arg0) {
        }
    });
于 2012-07-20T13:03:22.413 回答