cuốn sách gpt4 ai đã làm

java - JFace Dialog 在仍在使用时处理小部件

In lại Tác giả: Walker 123 更新时间:2023-11-29 05:08:36 27 4
mua khóa gpt4 Nike

我有一个扩展 jface.dialogs.Dialog 的类。在该对话框中有一个保存按钮。当用户按下那个按钮时,我需要从一些 swt.widgets.Text 字段中读取值,但是文本字段已经被处理掉了。

Tôi đã làm gì sai?

public class MyNewDialog extends Dialog {
private Text txt;

public MyNewDialog(Shell parentShell) {
super(parentShell);
}

@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
container.setLayout(new GridLayout(2, false));

txt = new Text(container, SWT.BORDER);
txt.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

return container
}

@Override
protected void createButtonsForButtonBar(Composite parent) {
Button saveButton = createButton(parent, IDialogConstants.OK_ID, "Save", true);
saveButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent p_e) {
String string = txt.getText() //widget is disposed exception
}
}
}

câu trả lời hay nhất

由于您正在为按钮使用 IDialogConstants.OK_ID,因此您可以使用 okPressed() 方法。无需添加特定的监听器。

@Override
protected void okPressed()
{
value = txt.getText();

super.okPressed();
}

然后创建一个getter方法方法来返回giá trị变量:

public String getValue()
{
giá trị trả về;
}

关于java - JFace Dialog 在仍在使用时处理小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29537726/

27 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress