Bug 561965 - [win32] Adding an image to any column of a table adds the width of the image to the width of the first column
Summary: [win32] Adding an image to any column of a table adds the width of the image ...
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.15   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-09 13:18 EDT by Dieter Mai CLA
Modified: 2021-03-24 16:56 EDT (History)
1 user (show)

See Also:


Attachments
Image of NOK result (3.24 KB, image/png)
2020-04-09 13:18 EDT, Dieter Mai CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dieter Mai CLA 2020-04-09 13:18:03 EDT
Created attachment 282400 [details]
Image of NOK result

How to reproduce:
- Have a table with multiple columns
- Create a table item
- Add a short text to the first cell of the table item
- add a image with significant width to any column but the first
- invoke pack() on any column 

Observed result:
- [1] [NOK] The cells of the first column is displayed with an empty space on the left followed by the short text. The width of the empty space is similar to the width of the image that was added to the second column
- [2] [OK] The cells of the second column display the added image

Expected result
- [1] The first cell should only contain the added text.

Tested NOK on windows 10 with SWT lib 4.12, 4.13, 4.14 , 4.15 and swt-I20200409-0200

Tested OK on linux 64 MINT with SWT lib 4.15

I did no other tests.

Minimal code example:
// START OF CODE
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class SwtImageInTableTest {

	 public static void main(String[] args) {
         Display display = new Display ();
         Shell shell = new Shell (display);
         shell.setLayout(new GridLayout());
         Table table = new Table (shell, SWT.NONE);
         table.setLinesVisible(true);
         table.setHeaderVisible(true);

         TableColumn columnWithText = new TableColumn (table, SWT.NONE);
         columnWithText.setText ("Text");

         TableColumn columnWithImage = new TableColumn (table, SWT.NONE);
         columnWithImage.setText ("Image");

         int count = 3;
         for (int i=0; i<count; i++) {
             TableItem item = new TableItem (table, SWT.NONE);
             item.setText (0, "Text");
             item.setText (1, "Image");
             item.setImage(1, createImage());
         }

         columnWithText.pack();
         columnWithImage.pack();

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

     private static Image createImage() {
         Image image = new Image(Display.getCurrent(), 200, 20);
         GC gc = new GC(image);
  gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
         gc.fillRectangle(image.getBounds());
         gc.dispose();
         return image;
     }
}

// END OF CODE
Comment 1 Dieter Mai CLA 2021-03-24 16:56:23 EDT
Retested with SWT 4.19. The issue still occurs.