I noticed that JFace TableViewer has some troubles with displaying text in the first column (only) if other cells in other columns contain icons. Additional space before text appears. I don't think this issue has not been found yet, so possibly some additional configuration is required. Here is a sample:
And simple code to test:
public class IconTest {
private static class MyContentProvider implements IStructuredContentProvider {
public Object[] getElements(Object inputElement) {
return new String[] { "one", "two", "three", "four", "five", "six", "seven", "eight",
"nine", "ten" };
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
}
/**
* @param args
*/
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
TableViewer v = new TableViewer(shell, SWT.FULL_SELECTION);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
v.setContentProvider(new MyContentProvider());
CellLabelProvider labelProvider = new CellLabelProvider() {
public void update(ViewerCell cell) {
cell.setText(cell.getElement().toString());
}
};
CellLabelProvider labelProvider2 = new CellLabelProvider() {
public void update(ViewerCell cell) {
cell.setText(cell.getElement().toString());
cell.setImage(Display.getDefault().getSystemImage(SWT.ICON_QUESTION));
}
};
TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
column.setLabelProvider(labelProvider);
column.getColumn().setText("Column 1");
column.getColumn().setWidth(100);
TableViewerColumn column2 = new TableViewerColumn(v, SWT.NONE);
column2.setLabelProvider(labelProvider2);
column2.getColumn().setText("Column 2");
column2.getColumn().setWidth(100);
v.setInput("");
shell.setSize(400, 400);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
Any ideas?
This is a long standing known issue - see Eclipse bug report 43910 (from 2004!)
The bug report is saying that the underlying Windows table code behaves like this and there is nothing SWT/JFace can do about it.
You may be able to work around this by using OwnerDrawLabelProvider
which provides full control of how the cell is drawn. StyledCellLabelProvider
is derived for OwnerDrawLabelProvider
and is easier to use.