Hide empty last column from Table/Tree Viewer

1. How to remove last vestigial column from TableViewer
You might have seen that there is dummy or vestigial column in the TableViewer (as marked by the red oval in the below figure) which  is annoying at times because not only it look ugly but more so it occupy;s the precious  real state from your component/control like shown in figure below:




Solution: You can use TableColumnLayout from org.eclipse.jface.layout package inside org.eclipse.jface plugin which allows to layout the columns in your TableViewer in essentially two ways:

  1. Firstly via mentioning the width in pixel for each column present in the Viewer 
  2. Secondly, we could mentioned weights
The data could be supplied to the layout via of the implementation of ColumnLayoutData. The following snippet shows how to achieve it:

tableColumnLayout.setColumnData(tableColumn, new ColumnWeightData(1));


Explanation of the above line:

  1. tableColumnLayout is instance of ColumnLayoutData
  2. tableColumn is the column on which LayoutData need to be set in the Viewer
  3. ColumnWeightData(1) assign the weight of 1 to the column (this weight comes in to play when Viewer is resized so e.g. if two columns are there with weight's 2 & 1 they shrink or expand in the same ration)
  4. Instead of  ColumnWeightData we could also use ColumnPixelData which will be the fixed width of the column

Comments

Popular posts from this blog

java.net.SocketException: Connection reset

Spring: implements interface not working in @Controller