简体   繁体   English

使用 SWT 在我的窗口中心放置一个表格行

[英]Position a Table Row in the Center of my Window using SWT

I have a large table created with Java SWT which I can sort columnwise in various ways.我有一个用 Java SWT 创建的大表,我可以用各种方式对它进行列排序。 But whenever I sort a column, the table starts displaying the 1st row and I could not find a way to move the table to display a specific row, eg the last selected row.但是每当我对一列进行排序时,表格就会开始显示第一行,而我找不到移动表格以显示特定行的方法,例如最后选择的行。

Any idea is appreciated!任何想法表示赞赏! Gerald杰拉德

You can use `Table.setTopIndex" to set the row shown at the top of the table window. So to centre a row you might use something like:您可以使用“Table.setTopIndex”来设置显示在表格窗口顶部的行。因此,要使行居中,您可以使用以下内容:

static void showCentredRow(Table table, int rowToShow)
{
  Rectangle clientArea = table.getClientArea();
  int itemHeight = table.getItemHeight();
  int visibleRows = clientArea.height / itemHeight;

  int topRow = Math.max(rowToShow - (visibleRows / 2), 0);
 
  table.setTopIndex(topRow);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM