Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 345411

Summary: Table.pack() makes column width too small by one pixel
Product: [Eclipse Project] Platform Reporter: Markus Schorn <mschorn.eclipse>
Component: SWTAssignee: Felipe Heidrich <eclipse.felipe>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipse.felipe, helmut.haigermoser, mober.at+eclipse, Silenio_Quarti
Version: 3.6.2Flags: Silenio_Quarti: review+
Target Milestone: 3.7.1   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
patch none

Description Markus Schorn CLA 2011-05-11 08:38:47 EDT
On Windows 7, when adding a listener for the event type SWT.MeasureItem, the method TableColumn.pack() for all but the first column makes the column too small by one pixel. The column shows 'the...' instead of 'there'. 

I can reproduce the problem with the code below compiled with org.eclipse.swt.win32.win32.x86_3.6.2.v3659c.jar or
org.eclipse.swt.win32.win32.x86_3.7.0.v3730b.jar

I do not see the problem on Windows XP. Also, the problem goes away when removing the listener.


Sample code:
============
public class Main {
    public static void main(String[] args) {
        try {
            Display display = new Display();
            Shell shell = new Shell(display);
            shell.setLayout(new FillLayout());
            final Table table = new Table(shell, SWT.NONE);
            table.setHeaderVisible(true);
            table.addListener(SWT.MeasureItem, new Listener() {
                @Override
                public void handleEvent(Event event) {
                }
            });
            TableColumn column1 = new TableColumn(table, SWT.NONE);
            TableColumn column2 = new TableColumn(table, SWT.NONE);
            for (int i = 0; i < 10; i++) {
                TableItem item = new TableItem(table, SWT.NONE);
                item.setText(new String[] {"hi", "there"});
            }
            column1.pack();
            column2.pack();
            shell.setSize(300, 300);
            shell.open();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch()) display.sleep();
            }
            display.dispose();
        } catch (Throwable th) {
            System.out.println(th);
        }
    }
}
Comment 1 Felipe Heidrich CLA 2011-05-12 15:45:52 EDT
Created attachment 195537 [details]
patch
Comment 2 Helmut J. Haigermoser CLA 2011-07-27 07:43:47 EDT
(In reply to comment #1)
> Created attachment 195537 [details]
> patch

CQ:WIND00290158
Wow, this patch is really small, can we get a comment from the swt team about this, will this be picked up for 3.8, or even 3.7.x?
Thanks !:)
Helmut
Comment 3 Felipe Heidrich CLA 2011-07-27 13:56:44 EDT
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=e52152f77be1cc7518d934f5aa3f0bc7ae6ccc0e

fixed

thanks for reminding me about this bug.
Comment 4 Helmut J. Haigermoser CLA 2011-07-28 03:46:12 EDT
(In reply to comment #3)
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=e52152f77be1cc7518d934f5aa3f0bc7ae6ccc0e
> 
> fixed
> 
> thanks for reminding me about this bug.

Sure thing, thank you for doing all the work, Felipe! :)
Any chance we could get this into the 3.7 maintenance branch, is there any risk involved?
Helmut
Comment 5 Felipe Heidrich CLA 2011-07-28 15:21:07 EDT
backported
Comment 6 Helmut J. Haigermoser CLA 2011-07-29 02:04:13 EDT
(In reply to comment #5)
> backported

Thanks Felipe! :)
Comment 7 Felipe Heidrich CLA 2011-08-25 14:39:09 EDT
Verified in Version: 3.7.1 Build id: M20110825-0847