Prevent JFace TableColumn from being resized to 0 width

eclipse-rcp, java, jface

Solution

`Table` has no built-in support for this. So a `Resize` listener - like you have shown in your question - is the only way.

Problem

I am using a JFace TableViewer and TableColumnLayout. How can i set a columns minimum width, or at least prevent it from being resized to 0 width? ``` TableColumnLayout layout = new TableColumnLayout(); parent.setLayout(layout); TableViewer viewer = new TableViewer(parent, SWT.FULL_SELECTION | SWT.BORDER); //adding a few columns like this TableColumn col = new TableColumn(viewer.getTable(), SWT.LEFT); int minWidth = 100; layout.setColumnData(col, new ColumnWeightData(10, minWidth, true)); col.setMoveable(true); ... ``` It appears that the minWidth parameter of ColumnWeightData is not honored, i can still resize the columns to 0 width. Using something like this works: ``` col.addControlListener(new ControlListener(){ @Override public void controlMoved(ControlEvent e) { } @Override public void controlResized(ControlEvent e) { if(col.getWidth()<5) col.setWidth(5); }}); ``` But that seems rather ugly, is there a cleaner way to do it?

Original source