Community
Participate
Working Groups
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:
What does "incorrect" mean?
It shows a dialog with "height = 3610"
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(); } }
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(); } }
I could have swore their was a snippet for this ... better create one.
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?
will look at this during 3.4
Removing milestone. We simply ran out of time.
As per http://wiki.eclipse.org/Platform_UI/Bug_Triage_Change_2009
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.
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.