JFace TableViewer get visible column width

2c00L

I have a TableViewer with horizontal scrollbar. Moving the scrollbar or re-sizing window can hide or show certain columns.

I want to know if a certain column is visible after scrolling and if so, its exact width that is visible.

Any way to do it?

Rüdiger Herrmann

You need to query the underlying Table (viewer.getTable()) and its TableColumns (table.getColumns()) to solve this.

If you defined the viewers columns using TableViewerColumns the columns are also accessible through viewerColumn.getColumn().

To determine the rightmost visible column, you can use the width of the table's clientArea (Table#getClientArea().width) that gives you the total available space to show columns.

Each column has a width TableColumn.getWidth(). Adding all the widths of the columns that are left of the desired one, will enable you to dermine if it is visible.

table.getHorizontalBar().getSelection() gives you the horizontal offset of the rows. When substracting this offset you should be able to dermine if a given column is visible.

The resulting code would look like this:

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;
}

Note that if the columns can be re-ordered you need to determine the actual columnIndex through table.getColumnOrder()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

JFace TableViewer get multiple selected rows

From Dev

JFace TableViewer get multiple selected rows

From Dev

Sort JFace TableViewer by Multiple Columns

From Dev

jface tableviewer tooltip text cut

From Dev

what is difference between ColumnLabelProvider and ITableLabelProvider in Jface tableviewer?

From Dev

How to lock swt Table or Jface tableviewer scrollbar

From Dev

JFace TableViewer draw a rectangle on cell like Excel

From Dev

SWT/JFace TableViewer not showing Unicode characters

From Dev

How to preserve selections in a JFace TableViewer when refreshing?

From Dev

How can I create a checkbox in a TableViewer of JFace?

From Dev

JFace TableViewer - How to set the size to display one row only?

From Dev

How can I set an EList as an input in JFace TableViewer?

From Dev

JFace tableViewer checkbox selection returns null in eclipse e4

From Dev

JFace TableViewer - how to properly fireSelectionChanged() after calling setInput(...)?

From Dev

How do I select a single cell in Jface TableViewer?

From Dev

How to get the height and width of the visible browser area

From Dev

Get visible row and column number

From Dev

Add listener to TableViewer editing column

From Dev

How to get QTableView column width

From Dev

unable to set column width after jtable becomes visible

From Dev

OK and Cancel button not visible in MessageDialog in JFace / SWT

From Dev

Sort JFace Treeviewer multiple column

From Dev

Last column gets oversized in jface

From Dev

How can I show the progress of a Jface TableViewer Refresh when using a filter?

From Dev

How can I show the progress of a Jface TableViewer Refresh when using a filter?

From Dev

How to get ToolTip in a ListViewer in JFace?

From Java

Get the column width by index instead of position

From Dev

How to get current width of highcharts column

From Dev

Get Column height and width and update on resize

Related Related

  1. 1

    JFace TableViewer get multiple selected rows

  2. 2

    JFace TableViewer get multiple selected rows

  3. 3

    Sort JFace TableViewer by Multiple Columns

  4. 4

    jface tableviewer tooltip text cut

  5. 5

    what is difference between ColumnLabelProvider and ITableLabelProvider in Jface tableviewer?

  6. 6

    How to lock swt Table or Jface tableviewer scrollbar

  7. 7

    JFace TableViewer draw a rectangle on cell like Excel

  8. 8

    SWT/JFace TableViewer not showing Unicode characters

  9. 9

    How to preserve selections in a JFace TableViewer when refreshing?

  10. 10

    How can I create a checkbox in a TableViewer of JFace?

  11. 11

    JFace TableViewer - How to set the size to display one row only?

  12. 12

    How can I set an EList as an input in JFace TableViewer?

  13. 13

    JFace tableViewer checkbox selection returns null in eclipse e4

  14. 14

    JFace TableViewer - how to properly fireSelectionChanged() after calling setInput(...)?

  15. 15

    How do I select a single cell in Jface TableViewer?

  16. 16

    How to get the height and width of the visible browser area

  17. 17

    Get visible row and column number

  18. 18

    Add listener to TableViewer editing column

  19. 19

    How to get QTableView column width

  20. 20

    unable to set column width after jtable becomes visible

  21. 21

    OK and Cancel button not visible in MessageDialog in JFace / SWT

  22. 22

    Sort JFace Treeviewer multiple column

  23. 23

    Last column gets oversized in jface

  24. 24

    How can I show the progress of a Jface TableViewer Refresh when using a filter?

  25. 25

    How can I show the progress of a Jface TableViewer Refresh when using a filter?

  26. 26

    How to get ToolTip in a ListViewer in JFace?

  27. 27

    Get the column width by index instead of position

  28. 28

    How to get current width of highcharts column

  29. 29

    Get Column height and width and update on resize

HotTag

Archive