我在单元格中使用带有编辑器(文本,组合和检查)的SWT表,我想要正确地将列调整为文本。我尝试了TableColumn的Pack方法,但它似乎不起作用。
以下是我使用的示例
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();
}
答案 0 :(得分:-2)
做这样的事情: 第一次
table.setRedraw(false) ;
并完成你的工作 在最后设置它是真的,像这样:
table.setRedraw(true);