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

Bug 46521

Summary: [Widgets] Table resizing with FormLayout
Product: [Eclipse Project] Platform Reporter: Jim Pyrich <pyrich>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact: Felipe Heidrich <eclipse.felipe>
Severity: normal    
Priority: P3 CC: carolynmacleod4, craneml
Version: 3.0Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Windows 2000   
Whiteboard: stalebug

Description Jim Pyrich CLA 2003-11-12 14:58:53 EST
When I call shell.pack() for the shell containing a Table in the following 
example, the table width increases.  If I remove the description of the 
rightmost column, it stays the same size.  I wonder whether it has something to 
do with the phantom column on the right.  In testing, I've seen the phantom 
column disappear & reappear depending on whether I call shell.pack().  I 
believe that it increases 16 pixels each time.  I would like to do away with 
the extra column.  It seems that a pack of TableColumn removes the column and a 
pack of the shell puts it back.


package com.sfisolutions.tests;

import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.custom.*;

public class TableResizeProblem {

	static Display display;
	static Shell shell;
		
public static void main(String[] args){

	display = new Display();
	shell = new Shell(display);
	
	FormLayout layout= new FormLayout();
	layout.marginWidth = 5;
	layout.marginHeight = 5;
	shell.setLayout(layout);
	shell.setText("Table resizing with FormLayout");

	final Composite displayArea = new Composite(shell, SWT.NULL);

	layout = new FormLayout();
	layout.marginWidth = 2;
	layout.marginHeight = 2;
	displayArea.setLayout(layout);

	final Composite composite = new Composite(displayArea, SWT.NONE);
	
	FormLayout groupLayout = new FormLayout();
	composite.setLayout(groupLayout);

	FormData formData = new FormData();
	formData.top = new FormAttachment(0,0);
	formData.left = new FormAttachment(0,0);
	formData.right = new FormAttachment(100,0);
	formData.bottom = new FormAttachment(100,0);
	composite.setLayoutData(formData);

	int styles = SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | 
SWT.CHECK;

	final Table table = new Table(composite, styles);
	table.setHeaderVisible(true);
	table.setLinesVisible(true);

	layout = new FormLayout();
	layout.marginWidth = 0;
	layout.marginHeight = 0;
	table.setLayout(layout);

	TableColumn tableColumn = new TableColumn(table, SWT.NONE, 0);
	tableColumn.setText("Select");
	tableColumn = new TableColumn(table, SWT.NONE, 1);
	tableColumn.setText("Check #");
	tableColumn = new TableColumn(table, SWT.NONE, 2);
	tableColumn.setText("Check Date");
	tableColumn = new TableColumn(table, SWT.NONE, 3);
	tableColumn.setText("Payee");
	tableColumn = new TableColumn(table, SWT.RIGHT, 4);
	tableColumn.setText("Cleared Cks.");
	tableColumn = new TableColumn(table, SWT.RIGHT, 5);
	tableColumn.setText("Outstanding");

	TableItem item = new TableItem (table, SWT.NULL);
	item.setText(0, "");
	item.setText(1, "168");
	item.setText(2, "10-06-2003");
	item.setText(3, "State Farm");
	item.setText(4, "146.35");
	item.setText(5, "");

	Button dataButton = new Button(composite, SWT.PUSH);
	dataButton.setText("Resize");
	dataButton.addSelectionListener(new SelectionAdapter() {
		public void widgetSelected(SelectionEvent e) {
			
			for (int i = 0; i < table.getColumnCount(); i++) {
				TableColumn tableColumn = table.getColumn(i);
				tableColumn.pack();
			}

			displayArea.pack();
			shell.pack();
		}
	});

	formData = new FormData();
	formData.top = new FormAttachment(0,5);
	formData.left = new FormAttachment(composite, 0, SWT.CENTER);
	formData.height = 175;
	table.setLayoutData(formData);

	formData = new FormData();
	formData.top = new FormAttachment(table, 5);
	formData.right = new FormAttachment(100,-5);
	dataButton.setLayoutData(formData);

	for (int i = 0; i < table.getColumnCount(); i++) {
		tableColumn = table.getColumn(i);
		tableColumn.pack();
	}

	displayArea.pack();

	shell.pack();
	shell.open();

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

}
Comment 1 Grant Gayed CLA 2003-11-12 17:49:53 EST
Car to investigate.  Note that I was able to make the strange behaviour stop by 
commenting out the six "tableColumn.setText("*");" lines in the snippet.
Comment 2 Jim Pyrich CLA 2003-12-12 17:46:41 EST
Are there any other tests that I can run to help with resolving this problem?
Comment 3 Michelle Crane CLA 2009-07-29 14:37:03 EDT
Is there any movement on this problem?  I've run into it recently; except that turning off the column descriptors does not fix it for me.
Comment 4 Carolyn MacLeod CLA 2009-07-30 14:42:46 EDT
I am not going to be able to get to this any time soon.
Reassigning to Felipe, since he is our newest Table expert.  :)
Thanks,
Carolyn
Comment 5 Felipe Heidrich CLA 2009-08-05 15:22:14 EDT
It works for me on XP.

I clicked the resize button several times and the table/composite/shell all kept the same sizes.

Is this a w2k only problem ?
Comment 6 Felipe Heidrich CLA 2009-08-17 16:48:47 EDT
Your bug has been moved to triage, visit http://www.eclipse.org/swt/triage.php for more info.
Comment 7 Leo Ufimtsev CLA 2017-08-03 12:34:13 EDT
This is a one-off bulk update. (The last one in the triage migration).

Moving bugs from swt-triaged@eclipse to platform-swt-inbox@eclipse.org and adding "triaged" keyword as per new triage process:
https://wiki.eclipse.org/SWT/Devel/Triage

See Bug 518478 for details.

Tag for notification/mail filters:
@TriageBulkUpdate
Comment 8 Eclipse Genie CLA 2019-11-11 08:29:55 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.