Java 使用编辑器调整SWT表的大小
我在单元格中使用带有编辑器(文本、组合和复选框)的SWT表,我想根据文本正确调整列的大小。我尝试了TableColumn的打包方法,但似乎不起作用 这是我使用的样本Java 使用编辑器调整SWT表的大小,java,swt,Java,Swt,我在单元格中使用带有编辑器(文本、组合和复选框)的SWT表,我想根据文本正确调整列的大小。我尝试了TableColumn的打包方法,但似乎不起作用 这是我使用的样本 public static void main( String[] args ) { Display display = new Display(); Shell shell = new Shell( display ); shell.setLayout( new FillLayout() ); Ta
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();
}
publicstaticvoidmain(字符串[]args)
{
显示=新显示();
外壳=新外壳(显示);
setLayout(新的FillLayout());
表格=新表格(shell,SWT.BORDER | SWT.MULTI);
表.setLinesVisible(真);
对于(int i=0;i<3;i++)
{
TableColumn column=新的TableColumn(表,SWT.NONE);
列。设置宽度(100);
}
对于(int i=0;i<12;i++)
{
新表项(表,SWT.NONE);
}
TableItem[]items=table.getItems();
对于(int i=0;i
执行以下操作:
首先
做好你的工作
最后,将其设置为真,如下所示:
table.setRedraw(true);
您应该使用TableViewer并进行编辑support@omidhaghighatgoo如果您确信这将起作用,那么请解释您将在何处使用这两个命令。理想情况下发布一个完整的工作示例。。。
table.setRedraw(true);