How to center align nebula grid column group header

190 Views Asked by At

I want to center align the column group text, so provided the SWT.CENTER style while creating the "GridColumnGroup" similar to the way we provide for GridColumn. However even after providing the CENTER style, column group text is shown Left aligned.

Code I tried:

GridColumnGroup columnGroup = new GridColumnGroup(grid,SWT.CENTER);
columnGroup.setText("Column Group");
GridColumn column1 = new GridColumn(columnGroup,SWT.CENTER);
column1.setText("Column 1");
GridColumn column2 = new GridColumn(columnGroup,SWT.CENTER);
column2.setText("Column 2");

[Nebula Grid column and column group rendering with above code ] 2 Any idea what I am missing here ?

Thanks

1

There are 1 best solutions below

0
On

The style SWT.CENTER does not propagate to the GridHeaderRenderer of the column group. However, void setHorizontalAlignment​(int alignment) method of GridHeaderRenderer allows you to center the text.

columnGroup.getHeaderRenderer().setHorizontalAlignment(SWT.CENTER);