本文主要是介绍自定义Dialog(org.eclipse.jface.dialogs.Dialog),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、继承Dialog类。
//JFace包和SWT包都有Dialog类,这里继承的是JFace的Dialog类
public class LoginDialog extends Dialog {public LoginDialog(Shell parentShell) {super(parentShell);setShellStyle(SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);}
}
2、 添加界面组件。
//在createDialogArea方法中构建Dialog的界面内容
@Override
protected Control createDialogArea(Composite parent)` {Composite container = new Composite(parent, SWT.NONE); GridLayout gLayout = new GridLayout(2, false);// 应用GridLayout布局container.setLayout(gLayout); // 添加文本标签 Label label_1 = new Label(container, SWT.NONE);label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));label_1.setText("用户:");// 添加文本框textUser = new Text(container, SWT.BORDER);textUser.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));textUser.setText("请输入用户名");Label lblNewLabel = new Label(container, SWT.NONE);lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));lblNewLabel.setText("密码:");textPassword = new Text(container, SWT.BORDER | SWT.PASSWORD);textPassword.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); textUser.setFocus(); return container;
}
3、 设置对话框按钮样式。
// 改写父类创建按钮的方法使其失效。//pa
这篇关于自定义Dialog(org.eclipse.jface.dialogs.Dialog)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!