Java FocusLost Event using Swing

0

I would like the message that is programmed to be shown once the JTexfield1 loses focus, does not show if I click outside of my application anywhere on my desktop. Here I put the sample code:

private void jTextField1FocusLost(java.awt.event.FocusEvent evt) {
    JOptionPane.showMessageDialog(null, "Hola "+jTextField1.getText());
}

Note: This is not the code of my application, I just put something very simple so that they get along better with the idea of what I need.

    
asked by Victor Alejandro 15.05.2017 в 19:57
source

1 answer

0

this can be done by adding a focusListener to your textfield

that is:

jtextfield1.addFocusListener(new FocusListener() {

        public void focusLost(FocusEvent arg0) {
            JOptionPane.showMessageDialog(null,"Hola"+jTextField1.getText());

        }

        public void focusGained(FocusEvent arg0) {
            // TODO Auto-generated method stub

        }
    });
    
answered by 21.07.2017 в 14:45