문제

In my first column of my table, the displayed value is offset from the left edge.

Example

enter image description here

Notice the offset of the date value compared to the ItemId value

TableViewerColumn col = new TableViewerColumn(this , SWT.NONE);
  col.getColumn().setWidth(125);
  col.getColumn().setText("Date Created");
  col.setLabelProvider(new ColumnLabelProvider() {
    @Override
    public String getText(Object element) {
       AplotSaveDataModel.SaveData p = (AplotSaveDataModel.SaveData) element;
      return p.getDateTime();
    }
  });

  col = new TableViewerColumn(this , SWT.NONE);
  col.getColumn().setWidth(100);
  col.getColumn().setText("ItemId");
  col.setLabelProvider(new ColumnLabelProvider() {
    @Override
    public String getText(Object element) {
       AplotSaveDataModel.SaveData p = (AplotSaveDataModel.SaveData) element;
      return p.getItemId();
    }
  });

Looking at the code above I do not see why they would be a difference?

도움이 되었습니까?

해결책

That's one of the very annoying SWT bugs when using windows. Here is the bug report. In windows, if the table contains an image which is not in the first column, the first column will show this "gap".

You can use a dirty fix by skipping the first column (not using it) and setting its width to zero.

As far as I remember correctly, this will introduce some minor glitches when using MacOS.


There is a very hacky work-around here as well.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top