2013-06-12 71 views
0

如何在SWT列表中显示行号?我没有提到有关显示StyledText行号的一些帖子,但它没有帮助我。SWT列表显示行号

在此先感谢!

回答

2

作为替代方案,你可以使用一个Table 2列无标题:

public static void main(String[] args) 
{ 
    Display display = new Display(); 
    final Shell shell = new Shell(display); 
    shell.setLayout(new GridLayout(1, false)); 

    Table table = new Table(shell, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION); 
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 
    table.setLinesVisible(false); 
    new TableColumn(table, SWT.RIGHT); 
    new TableColumn(table, SWT.NONE); 

    for (int row = 0; row < 20; row++) 
    { 
     TableItem item = new TableItem(table, SWT.NONE); 
     item.setText(0, row + ""); 
     item.setText(1, "Item " + row); 
    } 

    for(int col = 0; col < table.getColumnCount(); col++) 
    { 
     table.getColumn(col).pack(); 
    } 

    shell.pack(); 
    shell.open(); 
    while (!shell.isDisposed()) 
    { 
     if (!display.readAndDispatch()) 
      display.sleep(); 
    } 
    display.dispose(); 
} 

是这样的:

enter image description here

+0

这是一个非常聪明的解决办法确实如此。我想我现在可以使用这个了。但是,如果SWT列表有一种显示行号的方法,那将会非常有帮助。 谢谢Baz! – user2033666

+0

@ user2033666不客气。如果您找到解决方案,请返回并发布。如果没有,回来考虑接受我的回答:) – Baz