tags:

views:

532

answers:

1

I would like to draw the contents of a StyledText widget in to an Image; this will then provide a convenient way to stick the image into a Table cell.

Any suggestions about the best way to go about this?

A: 

Why do you want to create an image?

You could just render the the StyledText-widget in the table cell. If you have a lot of items and it is a performance problem you could create a virtual table by using SWT.VIRTUAL. If you're using JFace check out org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider.

If you're using plain SWT you should be able to use a TableEditor with a StyledText-widget as the editor. Something like this:

Table table = new Table(new Shell(new Display()), SWT.NONE);
table.setHeaderVisible (true);
TableColumn column = new TableColumn (table, SWT.NONE);
StyledText styledText = new StyledText(table, SWT.NONE);
TableItem item = new TableItem (table, SWT.NONE);
TableEditor editor = new TableEditor (table);
editor.grabHorizontal = true;
editor.grabVertical = true;
editor.setEditor (styledText, item, 0);
Kire Haglin
I am working to a framework that extends LabelProvider. The existing setup uses a SWT.PaintItem listener to paint styled text directly to the screen. I am looking for a more elegant approach; LabelProvider allows me to supply an Image for a cell, so I was hoping that I could easily squeeze an Image out of a StyledTextWidget.In the mean time I am simply creating my own Image, and painting styled text directly to that. The IStyledLabelProvider looks good though, I shall check that out. Thanks.
Ben Hammond
using setImage is definitely not what you want, as it is only useful if you need to paint some small images in front of the content of the cell. For anything else I'd rather use StyledText for rendering.
Roland Tepp