Resizing dialog question [message #641030] |
Tue, 23 November 2010 18:57  |
Eclipse User |
|
|
|
I have a JFace Dialog which has a couple Text inputs and a Label to display validation errors. When I set an error String on the Label I call getShell().pack() which nicely resizes the dialog to make the error Label visible. My problem is when I later remove the error String from the Label and call getShell().pack() the dialog resizes vertically but not horizontally. How can I get it to resize horizontally as well?
public class MyDialog extends org.eclipse.jface.dialogs.Dialog
{
...
protected Control createDialogArea(Composite parent)
{
Composite container = (Composite) super.createDialogArea(parent);
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
container.setLayout(new GridLayout(2, false);
errorLabel = new Label(container, SWT.RIGHT);
errorLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
...
}
protected void validate()
{
...
if(!valid)
{
errorLable.setText(LongMultiLineErrorString);
getShell().pack(); // resizes dialog vertically and horizontally
}
else
{
errorLabel.setText("");
getShell().pack(); // resizes dialog vertically but not horizontally
}
}
}
Is there a better way to do this? Is resizing the dialog bad practice? How would you suggest handling error messages otherwise?
Is there something about the GridDatas I've created that prevent the pack() from resizing the dialog horizontally?
Thanks,
Craig
[Updated on: Tue, 23 November 2010 20:50] by Moderator
|
|
|
|
|
|
Re: Resizing dialog question [message #642125 is a reply to message #641889] |
Mon, 29 November 2010 19:00  |
Eclipse User |
|
|
|
Hi Thomas, yes you are correct. It does show multi-line messages and scrolls the rest out of view. My mistake. As a bonus it's selectable and copyable too! This works well for our needs and we've adopted this as a standard for most of our dialogs. Thanks very much for the tip!
Craig
|
|
|
Powered by
FUDForum. Page generated in 0.06378 seconds