怎样在开发RCP中取得Text中的值?高手快来!我有个程序想取得dialog中的text的值!怎么做最好?会的快来呀!帮帮忙呀!谢了!!!!
[b]问题补充:[/b]
先谢过2位了!我先试试!!
Eclipse RCP
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
4条回答 默认 最新
iteye_14762 2008-08-10 10:59关注贴一个例子, 这个Dialog是继承自org.eclipse.jface.dialogs.Dialog:
[code="java"]public class TestDiaolog extends Dialog {private Text nameText; private String name; public TestDiaolog(Shell parentShell) { super(parentShell); } public Text getNameText() { return nameText; } public String getName() { return name; } protected Control createDialogArea(Composite parent) { Composite container = (Composite) super.createDialogArea(parent); nameText = new Text(container, SWT.BORDER); nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); return container; } protected void createButtonsForButtonBar(Composite parent) { createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); } @Override protected void okPressed() { // 如果OK被点击, 给name赋值 name = nameText.getText(); super.okPressed(); } protected Point getInitialSize() { return new Point(240, 180); }}[/code]下面是测试:
[code="java"] final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(500, 375);
shell.setText("SWT Application");
//
TestDiaolog dialog = new TestDiaolog(shell);
if (dialog.open() == Dialog.OK) {
MessageDialog.openInformation(shell, "Msg", dialog.getName());
/** 下面这句会抛 org.eclipse.swt.SWTException: Widget is disposed 异常, 因为TestDiaolog此时关闭, Text也随之销毁* */
MessageDialog.openInformation(shell, "Msg", dialog.getNameText().getText());
}
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
[/code]本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报