textField 获得焦点 弹出对话框,失去焦点关闭对话框

来源:互联网 发布:身份证分期借款软件 编辑:程序博客网 时间:2024/05/16 08:08

关于设置swing组件 textField  获得焦点 弹出对话框,失去焦点关闭对话框:

1.在对话框(latS)设置焦点失去事件:

 

latS.addFocusListener(new FocusAdapter() {public void focusLost(final FocusEvent arg0) {getExit();}}); 
public void getExit(){   this.dispose();  }

 2.在textField组建设置焦点失去 focusLost事件:(注意,不要设置成了public void focusGained(final FocusEvent arg0)事件,我就是在此折腾了好久)

JTextField wvwvLocation  = new JTextField();wvLocation.addFocusListener(new FocusAdapter() {public void focusGained(final FocusEvent e) {if(lld!=null){wvLocation.setText(lld.getLonD().getText()+"°"+lld.getLonM().getText()+"′"+lld.getLonS().getText()+"\""+" E;"+              lld.getLatD().getText()+"°"+lld.getLatM().getText()+"′"+lld.getLatS().getText()+"\""+" N");lld.getExit();lld = null;}else{lld = new LonLatFrm();lld.setLocationRelativeTo(wvLocation);lld.setVisible(true);}}});

  

原创粉丝点击