Nebula gridTableViewer cell content should wrap

766 views Asked by At

I am using nebula gridTableViewer for my application, in its cell some time content is so lengthy, so I want to show as WRAP (in multiline). I did changes for it but it is not reflecting:

I added SWT.WRAP but not works, I tried to wrap the text in LabelProvider too but it also not works so how could i do it?

Should i need to add listener for this.

1

There are 1 answers

0
Monikka On

Adding SWT.WRAP to the gridTableViewer would not cause the Text in the grid cells to wrap. gridColumn.setWordWrap(true) causes the text entered in the cell to be wrapped after the entered value is applied to the editor(setvalue called). To wrap the text interactively, SWT.WRAP should be added as a style to the TextCellEditor or to Text widget placed in the cells.

gridViewerColumn.getColumn.setWordWrap(true);
gridTableViewer.setEditingSupport(new EditingSupport(gridTableViewer) {
....
    @Override
    protected CellEditor getCellEditor(Object element) {
        TextCellEditor cellEditor = new TextCellEditor(gridTableViewer.getGrid(),
                                    SWT.WRAP)
        return cellEditor;
    }

Or

....
final GridItem item = grid.getItem(grid.getTopIndex());
for (int i = 0; i < grid.getColumnCount(); i++) {
    final Text text = new Text(grid, SWT.WRAP);
    Listener textListener = new Listener() {
        public void handleEvent(final Event e) {
            switch (e.type) {
                case SWT.FocusOut:
                item.setText(column, text.getText());
                ....
            }
        }
    }
}

I have used the SWT.WRAP in the TextCellEditor before, and it works.