private void configureTableResizing ( final Composite parent , final Table table , final TableColumn column1 , final TableColumn column2 ) { parent . addControlListener ( new ControlAdapter ( ) { public void controlResized ( ControlEvent e ) { Rectangle area = parent . getClientArea ( ) ; Point preferredSize = table . computeSize ( SWT . DEFAULT , SWT . DEFAULT ) ; int width = area . width - 2 * table . getBorderWidth ( ) ; if ( preferredSize . y > area . height ) { // Subtract the scrollbar width from the total column // width // if a vertical scrollbar will be required Point vBarSize = table . getVerticalBar ( ) . getSize ( ) ; width -= vBarSize . x ; } Point oldSize = table . getSize ( ) ; if ( oldSize . x > width ) { // table is getting smaller so make the columns // smaller first and then resize the table to // match the client area width column1 . setWidth ( width / 2 ) ; column2 . setWidth ( width / 2 ) ; table . setSize ( width , area . height ) ; } else { // table is getting bigger so make the table // bigger first and then make the columns wider // to match the client area width table . setSize ( width , area . height ) ; column1 . setWidth ( width / 2 ) ; column2 . setWidth ( width / 2 ) ; } } } ) ; }
Correctly resizes the table so no phantom columns appear