Slide 1
Slide 2
Slide 3

Focus Event in java programming (V68)

No Comments

FocusEvent

FocusEvent is a class in Java that represents an event which occurs when a component gains or loses the input focus.
It is generated when a GUI component, such as a text field, button, or other focusable component, becomes the active component to receive keyboard input or when it no longer has that focus.

Example: 

Source Code:
Copied!
    private void jTextField1FocusGained(java.awt.event.FocusEvent evt) {                                        
         jTextField1.setBackground(java.awt.Color.YELLOW);
         jLabel1.setText("Focus In");
    }                                       

    private void jTextField1FocusLost(java.awt.event.FocusEvent evt) {                                      
        jTextField1.setBackground(java.awt.Color.GREEN);
        jLabel1.setText("Focus Out");
    }                                                                                

Result:

Watch the video:

Ebook: https://softkhpc.blogspot.com/2025/05/java-programming-ebooks.html

back to top