Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Resize SWT table with editors
Resize SWT table with editors [message #1262541] Mon, 03 March 2014 18:58
Testr t is currently offline Testr t
Messages: 93
Registered: April 2013
Member
I am using a SWT table with editors(Text, Combo and Check) in the Cells and I want to resize the columns correctly to the text. I tried the TableColumn's Pack method but it doesnt seem to work.

Here is the sample that I use
 public static void main( String[] args )
    {
        Display display = new Display();
        Shell shell = new Shell( display );
        shell.setLayout( new FillLayout() );
        Table table = new Table( shell, SWT.BORDER | SWT.MULTI );
        table.setLinesVisible( true );
        for ( int i = 0; i < 3; i++ )
        {
            TableColumn column = new TableColumn( table, SWT.NONE );
            column.setWidth( 100 );
        }
        for ( int i = 0; i < 12; i++ )
        {
            new TableItem( table, SWT.NONE );
        }
        TableItem[] items = table.getItems();
        for ( int i = 0; i < items.length; i++ )
        {
            TableEditor editor = new TableEditor( table );
            CCombo combo = new CCombo( table, SWT.NONE );
            combo.setText( "CCombo" );
            combo.add( "item  1" );
            combo.add( "A very lengthyyyyyyyyy item 2" );
            editor.grabHorizontal = true;
            editor.setEditor( combo, items[i], 0 );
            editor = new TableEditor( table );
            Text text = new Text( table, SWT.NONE );
            text.setText( "A very lengthyyyyyyyy  text" );
            editor.grabHorizontal = true;
            editor.setEditor( text, items[i], 1 );
            editor = new TableEditor( table );
            final Button button = new Button( table, SWT.CHECK );
            button.pack();
            editor.minimumWidth = button.getSize().x;
            editor.horizontalAlignment = SWT.LEFT;
            editor.setEditor( button, items[i], 2 );
        }
        //resize columns
        for ( TableColumn columm : table.getColumns() )
            columm.pack();
        
        shell.pack();
        shell.open();
        while ( !shell.isDisposed() )
        {
            if ( !display.readAndDispatch() )
                display.sleep();
        }
        display.dispose();
    }
Previous Topic:Re: Plugin installation with XULRunner 24
Next Topic:SWT 4.4 M5 and XULRunner 24
Goto Forum:
  


Current Time: Fri Oct 24 08:31:30 GMT 2014

Powered by FUDForum. Page generated in 0.01511 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software