I have a SWT table which wrapped by the JFace TableViewer, but this problem also applies to org.eclipse.swt.widgets.Table.
When I use a StyledCellLabelProvider, the text is always left aligned, even when I use
colA.getColumn().setAlignment(SWT.RIGHT);
Here is the label provider and setup:
TableViewerColumn colA = new TableViewerColumn(measureTable, SWT.NONE);
colA.setLabelProvider(new StyledCellLabelProvider() {
@Override
public void update(ViewerCell cell) {
ModelItem item = (ModelItem) cell.getElement();
cell.setFont(FONT_REGISTRY.get(MY_SPECIAL_FONT));
cell.setText(item.getText());
super.update(cell);
}
});
Any sort of workaround would be great. For e.g, nesting a widget inside the table and right aligning the text in the widget somehow.
Platform: Windows 7
You found a bug in
StyledCellLabelProvider. It will not occur with any otherCellLabelProvider.StyledCellLabelProvideruses “owner draw” for drawing theTablecells. That means, the cell content is not drawn natively by the OS. It is drawn in anSWT.PaintItemevent by the Table “owner”.StyledCellLabelProviderdoes not respect the alignment of theTableColumn. You can see the source here, the methodgetTextLayoutForInfo(.)is of interest.A workaround could be to copy that class, fix the bug by adding
in the method
getTextLayoutForInfo(.)(I didn’t test this fix, but if it doesn’t work, you should get the idea, and be able to make it work)You should also add a bug report: Eclipse Bugzilla