Resizing dialog question [message #641030] |
Tue, 23 November 2010 23:57 |
|
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: Wed, 24 November 2010 01:50] Report message to a moderator
|
|
|
Re: Resizing dialog question [message #641133 is a reply to message #641030] |
Wed, 24 November 2010 11:19 |
|
Hi Craig,
maybe you should use SWT.WRAP or SWT.MULTI when creating your label, so you don´t have to resize it. The error message will be displayed in multiple lines if there is no space left.
A second way would be to extend from TitleAreaDialog, and display the error in the titlebar, like most of the eclipse dialogs do
I think resizing is a really bad thing for dialogs, especially regarding the usability.
Greetz
Thomas
|
|
|
Re: Resizing dialog question [message #641207 is a reply to message #641133] |
Wed, 24 November 2010 14:46 |
|
Thanks for replying Thomas. I changed the Label declaration to SWT.MULTI | SWT.RIGHT | SWT.WRAP and now all I get is a thin vertical line where the Label should be. It doesn't resize on pack() and so the message is never visible. What am I doing wrong there?
My instinct told me that resizing the dialog is not a good usability thing too but how else can you display an error message that the current dialog size can't accommodate? I'm intrigued by the TitleAreaDialog but again it will only show text up to the width of the dialog which in some cases won't be enough - and it can't display multiple lines.
Still open for ideas though
Craig
|
|
|
Re: Resizing dialog question [message #641889 is a reply to message #641207] |
Mon, 29 November 2010 07:11 |
|
Hi Craig,
just use SWT.MULTI, i also had the effect that the label won´t be displayed correctely if you use SWT.MULTI AND SWT.WRAP. (Maybe also try to use only SWT.WRAP)
The TitleArea should be able to display Multiline messages, which method did you use?
void org.eclipse.jface.dialogs.TitleAreaDialog.setMessage(String newMessage, int newType)
Usually 3 lines of text can be shown, but NOT more (depends also on the size of the TitleBar).
I think you should try again both ways, or post a code snippet.
Greetz
Thomas
|
|
|
Re: Resizing dialog question [message #642125 is a reply to message #641889] |
Tue, 30 November 2010 00:00 |
|
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.01998 seconds