Community
Participate
Working Groups
I use a TableViewer to create a table containing several rows of data. As part of this I wish to "grey out" some selected cells in the table. To do this I use a new GC placed on the table, and get the location of the cell to draw a rectangle on by calling the getBounds(index) on the table item in the table. On windows this produces the correct behaviour, and the grey cell is perfectly aligned with the required cell. On linux-gtk, the bound box appears to be out by the size of the column heading titles. Additionally if you use a table, rather than a TableViewer() the cells almost line up but they appear to be out by a few pixels on linux (see tablebug_linux.jpg attached file). It would appear that the getBounds(index) call is not returning the correct bounding rectangle in either case. Below is the code needed to draw a simple table, it should highlight the cell containing the words "item 1 col 1" as seen in the windows screen shot, but on linux it draws the box in completely the wrong place. Windows eclipse: 3.0.0 - 200406192000 Linux eclipse: 3.0.1 - 200409161125 To re-create do the following: 1) Create a simple plugin, using the plugin with view wizard 2) replace the SampleView code with the code attached to the bug Relevant painting section of the code is below: private void paintGreyCells() { // For each row... for (int i = 0; i < viewer.getTable().getItemCount(); i++) { // Get the table item, and check text to see if we grey it out TableItem tableItem = viewer.getTable().getItem(i); if (tableItem.getText(1).equals("item 1 col 1")) { tableItemGC.fillRectangle(tableItem.getBounds(1)); } } }
Created attachment 14883 [details] windows correctly highlighting the grey cell
Created attachment 14884 [details] linux-gtk incorrectly highlighting the grey-cell
Created attachment 14886 [details] Incorrect alignment of cell in a table (as opposed to TableViewer)
Created attachment 14890 [details] Source code for modified SampleView.java
Note that there's new api on TableItem in 3.0 for setting an individual cell's foreground, background and font. This might be an easier approach. *** This bug has been marked as a duplicate of 42416 ***