다음 코드로 두 개의 입력 필드가있는 Dialog를 만들었습니다.Jface 대화 상자를 사용하여 텍스트의 유효성을 검사하는 방법은 무엇입니까?
public class CCIDDialog extends TitleAreaDialog {
private Text ccidText;
private Text descriptionText;
private String CCID;
private String description;
public CCIDDialog(Shell parentShell) {
super(parentShell);
}
public void create() {
super.create();
setTitle(_title);
setMessage("Bitte geben Sie die CCID "+firstchar+"xxxxxxx und eine Beschreibung ein (max. 7-stellig): ", IMessageProvider.INFORMATION); }
@Override
protected Control createDialogArea(Composite parent) {
Composite area = (Composite) super.createDialogArea(parent);
Composite container = new Composite(area, SWT.NONE);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout(2, false);
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
container.setLayout(layout);
createCCID(container);
createDescription(container);
return area;
}
private void createCCID(Composite container) {
Label lbtFirstName = new Label(container, SWT.NONE);
lbtFirstName.setText("CCID (ohne "+firstchar+"): ");
GridData dataCCID = new GridData();
dataCCID.grabExcessHorizontalSpace = true;
dataCCID.horizontalAlignment = GridData.FILL;
ccidText = new Text(container, SWT.BORDER);
ccidText.setLayoutData(dataCCID);
}
private void createDescription(Composite container) {
Label lbtLastName = new Label(container, SWT.NONE);
lbtLastName.setText("Beschreibung: ");
GridData dataDescription = new GridData();
dataDescription.grabExcessHorizontalSpace = true;
dataDescription.horizontalAlignment = GridData.FILL;
descriptionText = new Text(container, SWT.BORDER);
descriptionText.setLayoutData(dataDescription);
}
@Override
protected boolean isResizable() {
return true;
}
// save content of the Text fields because they get disposed
// as soon as the Dialog closes
private void saveInput() {
CCID = ccidText.getText();
description = descriptionText.getText();
}
@Override
protected void okPressed() {
saveInput();
super.okPressed();
}
public String getCCID() {
return CCID;
}
public String getDescription() {
return description;
}
}
ccidtext의 유효성을 검사하는 방법이 있습니까? 사용자가 7 자 이상을 입력하면 알림을 받아야하며 대화 상자를 계속 진행할 수 없습니다. 인터넷에서 너무 많이 읽었지 만이 문제에 대한 해결책을 찾을 수 없습니다.
많은 도움을 주셔서 감사합니다.
당신은 텍스트가 변경 될 때마다 호출 될 ModifyListener
을 추가 Text.addModifyListener
을 사용할 수 있습니다
감사합니다 :) .setTextLimit (8) 직접 텍스트 필드에 대해 작동합니다 :) 거기에 최소 1자를 입력해야하는 필드를 설정하는 방법이 있습니까? – JonnyBeton