关于设置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);
}
}
});