Bug 167425 - [Dialogs] JFace dialog shows incorrect size
Summary: [Dialogs] JFace dialog shows incorrect size
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2006-12-11 09:50 EST by BensonN CLA
Modified: 2019-09-06 15:37 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description BensonN CLA 2006-12-11 09:50:08 EST
Build ID: 3.2.1

Steps To Reproduce:
1. I created a dialog extends JFace TitleAreaDialog, when I bring it up, the size of dialog is incorrect. I tried it on Eclipse 3.2.1 and 3.3M, they are all same.

Here is my dialog code:

package mypackage;

import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

/**
 * Class: PropertyGroupDialog
 */
public class PropertyGroupDialog extends TitleAreaDialog
{
	public PropertyGroupDialog(Shell parentShell)
	{
		super(parentShell);
		setBlockOnOpen (true);
	}
	
	protected void initStore()
	{
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
	protected Control createDialogArea(Composite parent)
	{
		Composite primary = new Composite(parent, SWT.NONE);
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		primary.setLayout(layout);
		GridData gd = new GridData(GridData.FILL_BOTH);
		gd.widthHint = 50; // set width to the window in order to show the label in multiple lines.
		primary.setLayoutData(gd);

		Label label = new Label(primary, SWT.NULL | SWT.WRAP);
		label.setText("Label");
		gd = new GridData();
		gd.verticalAlignment = GridData.BEGINNING;
		label.setLayoutData(gd);
		
		Label labelText = new Label(primary, SWT.NULL | SWT.WRAP);
		labelText.setText("alksdflkajsdfjaslkfdjalskjfdlkasjfdlkajdsflkjaslkfdjalskfdjlksadjflkasjdflkjsalkfdjaslkfdjalksjfdlkasjfdlkasjfdlkajdsflkjdsaflkjsadlkfjaslkfdjlkdsajflkasdjflksajfdlkasjdflkjsadflkjsadlkfjsadlkfjaksjfdlkjsalkfdjlksdjflksjdflkjdsfaslkfdjlkfdsj");
		gd = new GridData(GridData.FILL_HORIZONTAL);
		labelText.setLayoutData(gd);
		
		return (primary);
	}
}


More information:
Comment 1 Steve Northover CLA 2006-12-11 11:47:02 EST
What does "incorrect" mean?
Comment 2 BensonN CLA 2006-12-11 11:53:10 EST
It shows a dialog with "height = 3610"
Comment 3 Steve Northover CLA 2006-12-11 12:04:14 EST
SWT only code:


import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class PR_167345 {
	protected static Control createDialogArea(Composite parent) {
		Composite primary = new Composite(parent, SWT.NONE);
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		primary.setLayout(layout);
		GridData gd = new GridData(GridData.FILL_BOTH);
		gd.widthHint = 50; // set width to the window in order to show the label in multiple lines.
		primary.setLayoutData(gd);
		Label label = new Label(primary, SWT.NULL | SWT.WRAP);
		label.setText("Label");
		gd = new GridData();
		gd.verticalAlignment = GridData.BEGINNING;
		label.setLayoutData(gd);
		Label labelText = new Label(primary, SWT.NULL | SWT.WRAP);
		labelText.setText("alksdflkajsdfjaslkfdjalskjfdlkasjfdlkajdsflkjaslkfdjalskfdjlksadjflkasjdflkjsalkfdjaslkfdjalksjfdlkasjfdlkasjfdlkajdsflkjdsaflkjsadlkfjaslkfdjlkdsajflkasdjflksajfdlkasjdflkjsadflkjsadlkfjsadlkfjaksjfdlkjsalkfdjlksdjflksjdflkjdsfaslkfdjlkfdsj");
		gd = new GridData(GridData.FILL_HORIZONTAL);
		labelText.setLayoutData(gd);
        return (primary);
	}

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new GridLayout());
		createDialogArea(shell);
		shell.pack();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		display.dispose();
	  }
}
Comment 4 Steve Northover CLA 2006-12-11 13:37:21 EST
It's not a bug.  Here is what is happening:  The size that gets computed for the shell is very long and thin (to see this, create a shell with no trim).  When we request this size from the operating system, the operating system returns a minimum size that is wider but still as tall as requested.  The way to fix this is to detect that the operating system did not honour your size request and try again with the minimimn size that is allowed.

Here is code that does what you want:


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

public class PR_167345 {
	protected static Control createDialogArea(Composite parent) {
		Composite primary = new Composite(parent, SWT.NONE);
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		primary.setLayout(layout);
		GridData gd = new GridData(GridData.FILL_BOTH);
		gd.widthHint = 50; // set width to the window in order to show the label in multiple lines.
		primary.setLayoutData(gd);
		Label label = new Label(primary, SWT.NULL | SWT.WRAP);
		label.setText("Label");
		gd = new GridData();
		gd.verticalAlignment = GridData.BEGINNING;
		label.setLayoutData(gd);
		Label labelText = new Label(primary, SWT.NULL | SWT.WRAP);
		labelText.setText("alksdflkajsdfjaslkfdjalskjfdlkasjfdlkajdsflkjaslkfdjalskfdjlksadjflkasjdflkjsalkfdjaslkfdjalksjfdlkasjfdlkasjfdlkajdsflkjdsaflkjsadlkfjaslkfdjlkdsajflkasdjflksajfdlkasjdflkjsadflkjsadlkfjsadlkfjaksjfdlkjsalkfdjlksdjflksjdflkjdsfaslkfdjlkfdsj");
		gd = new GridData(GridData.FILL_HORIZONTAL);
		labelText.setLayoutData(gd);
        return (primary);
	}
	public static void main(String[] args) {
		Display display = new Display();
		// change this to SWT.NONE to see that the dialog size is "right"
		//Shell shell = new Shell(display, SWT.NONE);
		Shell shell = new Shell(display);
		shell.setLayout(new GridLayout());
		createDialogArea(shell);
		Point preferredSize = shell.computeSize (SWT.DEFAULT, SWT.DEFAULT);
		shell.setSize (preferredSize);
		Point size = shell.getSize ();
		if (size.x > preferredSize.x) {
			int newWidth = Math.max (0, size.x - shell.computeTrim (0, 0, 0, 0).width);
			shell.setSize (shell.computeSize (newWidth, SWT.DEFAULT));
		}
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		display.dispose();
	}
}
Comment 5 Steve Northover CLA 2006-12-11 13:37:42 EST
I could have swore their was a snippet for this ... better create one.
Comment 6 BensonN CLA 2006-12-12 15:33:29 EST
It works for the stand alone SWT application, but when I put the code to where I call the dialog which is mentioned in the defect (after "create", before "open"), it still doesn't work, and another thing is If I put that Label to a composite which is used by a wizard or an editor, How can I handle that?
Comment 7 Susan McCourt CLA 2007-06-29 13:35:05 EDT
will look at this during 3.4
Comment 8 Susan McCourt CLA 2008-05-23 11:23:24 EDT
Removing milestone.  We simply ran out of time.
Comment 9 Susan McCourt CLA 2009-07-09 17:19:04 EDT
As per http://wiki.eclipse.org/Platform_UI/Bug_Triage_Change_2009
Comment 10 BensonN CLA 2010-09-23 11:57:54 EDT
Hi, 

Since it's been a while, any updates on this? We are still having the extra space problem for the pages which contain wrapped labels. Thanks for your time.
Comment 11 Eclipse Webmaster CLA 2019-09-06 15:37:27 EDT
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.