我有一個TableViewer
水平滾動條。移動滾動條或重新調整窗口大小可以隱藏或顯示某些列。JFace TableViewer顯示列寬
我想知道某個列在滾動後是否可見,如果是,它的確切寬度是可見的。
任何方式來做到這一點?
我有一個TableViewer
水平滾動條。移動滾動條或重新調整窗口大小可以隱藏或顯示某些列。JFace TableViewer顯示列寬
我想知道某個列在滾動後是否可見,如果是,它的確切寬度是可見的。
任何方式來做到這一點?
您需要查詢底層的Table
(viewer.getTable()
)及其TableColumn
(table.getColumns()
)才能解決此問題。
如果您使用TableViewerColumn
定義了查看者列,那麼也可以通過viewerColumn.getColumn()
訪問這些列。
要確定最右側的可見列,可以使用表的clientArea(Table#getClientArea().width
)的寬度,該寬度爲您提供顯示列的總可用空間。
每列的寬度爲TableColumn.getWidth()
。添加所需的所有列的寬度,將使您能夠清楚地看到它是否可見。
table.getHorizontalBar().getSelection()
爲您提供了行的水平偏移量。當減去這個偏移量時,如果給定的列是可見的,你應該能夠剝離它。
生成的代碼應該是這樣的:
boolean isColumnVisible(Table table, int columnIndex) {
int columnRight = 0;
for(int i = 0; i <= columnIndex; i++) {
columnRight += table.getColumn(i).getWidth();
}
int clientAreaWidth = table.getClientArea().width;
int horizontalOffset = table.getHorizontalBar().getSelection();
return columnRight - horizontalOffset <= clientAreaWidth;
}
注意,如果列可以被重新排序,你需要通過table.getgetColumnOrder()
大詳盡的解答,以確定實際
columnIndex
!我只需要偏移量,因爲我的列在索引0處。非常感謝。 – 2c00L