简体   繁体   中英

Java SWT TreeViewer with one column that needs to be StyledText

I have a TreeViewer used in an eclipse plugin that uses a content provider and a label provider that implements all of ( ITableLabelProvider , IFontProvider , IColorProvider ).

But I need one of the columns of the table it creates to hold "links" - underlined blue text that when clicked causes some popup to open. I guess what I want to do is cause that single column to hold styled text and not just text, and attach a listener to the items in that column of the tree, but I couldn't figure out how to do it.

Use a separate label provider for each column using TreeViewerColumn :

TreeViewer viewer = new TreeViewer(.....);

TreeViewerColumn col1 = new TreeViewerColumn(viewer, SWT.LEAD);

col1.setLabelProvider(col1 label provider);

... repeat for other columns

For columns that require styling use DelegatingStyledCellLabelProvider as the column label provider as described here

Note: Do not call viewer.setLabelProvider when using column label providers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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