4
A
回答
9
剛剛創建自己的Dialog
:
public static void main(String[] args) {
PasswordDialog dialog = new PasswordDialog(new Shell());
dialog.open();
System.out.println(dialog.getPassword());
}
public static class PasswordDialog extends Dialog {
private Text passwordField;
private String passwordString;
public PasswordDialog(Shell parentShell) {
super(parentShell);
}
@Override
protected void configureShell(Shell newShell)
{
super.configureShell(newShell);
newShell.setText("Please enter password");
}
@Override
protected Control createDialogArea(Composite parent) {
Composite comp = (Composite) super.createDialogArea(parent);
GridLayout layout = (GridLayout) comp.getLayout();
layout.numColumns = 2;
Label passwordLabel = new Label(comp, SWT.RIGHT);
passwordLabel.setText("Password: ");
passwordField = new Text(comp, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
passwordField.setLayoutData(data);
return comp;
}
@Override
protected void okPressed()
{
passwordString = passwordField.getText();
super.okPressed();
}
@Override
protected void cancelPressed()
{
passwordField.setText("");
super.cancelPressed();
}
public String getPassword()
{
return passwordString;
}
}
結果看起來是這樣的:
5
你也可以繼承InputDialog爲並覆蓋用於文本控件的樣式。
public class PasswordDialog extends InputDialog {
public PasswordDialog(Shell parentShell, String dialogTitle, String dialogMessage, String initialValue, IInputValidator validator) {
super(parentShell, dialogTitle, dialogMessage, initialValue, validator);
}
@Override
protected int getInputTextStyle() {
return super.getInputTextStyle() | SWT.PASSWORD;
}
}
相關問題
- 1. JFace的SWT InputDialog爲多行
- 2. WPF DevExpress TextEdit - 用於輸入密碼的「*」
- 3. 用於密碼輸入的Delphi輸入框?
- 4. 使用System.Diagnostics.Process輸入密碼
- 5. 基於輸入號碼隨機密鑰
- 6. 對於RSA密碼輸入太大BouncyCastle
- 7. 爲密鑰輸入密碼
- 8. UIWebView,輸入密碼
- 9. 陳舊的輸入被輸入密碼
- 10. 奇怪的輸入文本和輸入密碼擦除默認輸入密碼
- 11. 測試密碼的輸入
- 12. 密碼的隱形輸入?
- 13. JFace/SWT:更改InputDialog中按鈕的標籤
- 14. 輸入時隱藏輸入密碼(shell)
- 15. 值輸入密碼字段輸入值
- 16. 是否有任何用於密碼輸入的構件?
- 17. AWT/SWT中的IPhone密碼字段?
- 18. .htaccess提示輸入密碼
- 19. 輸入密碼字體-family
- 20. 多次輸入密碼
- 21. 在C中輸入密碼
- 22. 密碼輸入程序
- 23. 自動輸入密碼iphone
- 24. 螞蟻 - sshexec輸入密碼
- 25. 密碼輸入自定義
- 26. 提示輸入HTML密碼
- 27. JQuery驗證輸入密碼
- 28. 獲取shellcript輸入密碼
- 29. iPad輸入密碼視圖
- 30. 在Arduino中輸入密碼?
這是一個JFaces對話框而不是SWT對話框。當然相關,但並不完全回答這個問題。 – adamfisk
@adamfisk我不得不不同意。問題是要求輸入對話框,它是一個JFace對話框。這個問題沒有提到像「我只想要SWT對話框,沒有JFace」。 – Baz
你是對的 - InputTialog在SWT中不存在,所以JFaces肯定是隱含的和必需的 - 我站得更正! – adamfisk