其實我正在寫代碼。我想顯示消息對話框(不按任何按鈕)當我離開我的JTextField
但不知道如何做到這一點。請幫忙。我使用NetBeans。如何顯示消息當我離開JTextField在java
-1
A
回答
2
您可以使用Focus Listener API來實現。
在focusLost
事件中,您可以顯示您的對話框。從文檔
實施例:
public void focusLost(FocusEvent e)
{
displayMessage("Focus lost", e);
}
+0
謝謝,它的工作原理。 –
+0
@MustajeeburRehman:不客氣!我很高興它有幫助。 :) – Azeem
1
可以使用FocusListener類focusLost()方法。
簡單的例子:
import java.awt.FlowLayout;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class ExampleClass {
JFrame MainFrame;
JTextField textField1;
JTextField textField2;
public ExampleClass(){
MainFrame = new JFrame("Example");
MainFrame.setLayout(new FlowLayout());
textField1 = new JTextField(10);
textFieldFocus();
textField2 = new JTextField("Dummy text");
MainFrame.add(textField1);
MainFrame.add(textField2);
MainFrame.pack();
MainFrame.setVisible(true);
}
private void textFieldFocus() {
textField1.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
JOptionPane.showMessageDialog(null, "Done!");
}
@Override
public void focusGained(FocusEvent e) {}
});
}
public static void main(String[] args) {
new ExampleClass();
}
}
相關問題
- 1. 如何在JTextField中顯示默認消息java
- 2. 如何在離子選項卡離開3之前顯示確認消息
- 3. ANgular2-僅在用戶離開字段時顯示驗證消息
- 4. 當我的網站打開時彈出顯示消息
- 5. 如何在用戶離開時不顯示保存更改的警告消息
- 6. (FIXED)如果JTextField不包含數據顯示消息對話框
- 7. 如何僅當我提交查詢時顯示成功消息?
- 8. 如何使PowerShell的停止顯示,每當我推此消息
- 9. Java GUI - 顯示JTextField值
- 10. PHPmailer如何顯示消息
- 11. android - 如何顯示消息
- 12. 如何顯示Toast消息?
- 13. 當我離開應用程序時沒有收到GCM消息
- 14. jQuery驗證顯示錯誤消息(離開現場)
- 15. 顯示一條警告消息,然後離開網站鏈接
- 16. java - 我如何顯示JTextField中的字符數組
- 17. 當在WPF中展開TreeView時顯示「Please wait ..」消息
- 18. 在livejournal中顯示消息樹(java)
- 19. 消息離開datagridview時
- 20. 當在Java中關閉ExecutorService時顯示友好的消息?
- 21. 在Java中爲JTextField顯示事件?
- 22. 如何在ajax後顯示ckeditor消息
- 23. 如何在alt消息中顯示錶
- 24. 如何在SBT中顯示消息?
- 25. 如何顯示消息框在MVVM
- 26. 如何在javascript中顯示消息框
- 27. 如何在r中顯示消息?
- 28. 如何在LiveTV上顯示Toast消息
- 29. 如何在Maven中顯示消息
- 30. 如何在secondActivity中顯示Toast消息?
你可以分享你的代碼。代碼,你到目前爲止嘗試過。 – Blasanka
我還沒有寫代碼,但它的邏輯,我想實施我的代碼 –