简体   繁体   中英

How can I make a jlabel highlight when a mouse pointer is pointing at it in Java NetBeans

I am using Java NetBeans. I don't have that much of experience in programming. I am trying to make a label highlight when I point a mouse pointer on it.

I tried: Properties > events > mouse > focus gained .

Right click the Label -> Events -> Mouse -> MouseEntered

Add this code.

private void jLabel1MouseEntered(java.awt.event.MouseEvent evt) 
{                                     
    jLabel1.setOpaque(true);
    jLabel1.setBackground(Color.red);
}

Right click the Label -> Events -> Mouse -> MouseExited

Add this code.

private void jLabel1MouseExited(java.awt.event.MouseEvent evt) {                                    
    jLabel1.setBackground(Color.white);
    jLabel1.setOpaque(false);
}   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM