我有一个JFace对话框,这就是我打开的方式:
SampleDialog dialog = new SampleDialog(shell);
if(Window.OK == dialog.open())
{
// do something
if(condition)
{
MessageBox dialog = new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK| SWT.CANCEL);
dialog.setText("Sample");
dialog.setMessage("Some problem in processing");
}
else
{
// do something
}
}
如果控件转到if块,我不希望关闭对话框。怎么做到这一点?
答案 0 :(得分:4)
您应该通过覆盖对话框中的okPressed
方法来显示检查和消息框。
public class SampleDialog extends Dialog
{
@Override
protected void okPressed()
{
if (condition)
{
// TODO show your message box
}
else
{
// Allow the dialog to close
super.okPressed();
}
}
}
答案 1 :(得分:0)
覆盖JFace Dialog
close()
方法是另一种解决方法:
@Override
public boolean close()
{
if( condition )
{
if( this.getReturnCode() == OK )
{
MessageBox dialog = new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK| SWT.CANCEL);
dialog.setText("Sample");
dialog.setMessage("Some problem in processing");
return false;
}
}
return super.close();
}