hover effect in Java – Kensoft PH https://kensoftph.com Power up your knowledge in programming Mon, 07 Feb 2022 05:17:28 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.1 https://kensoftph.com/wp-content/uploads/2021/07/cropped-Kensoftph-New-logo-32x32.png hover effect in Java – Kensoft PH https://kensoftph.com 32 32 Java Hover Effect | 100% best for beginners https://kensoftph.com/java-hover-effect-tutorial-for-beginners/ https://kensoftph.com/java-hover-effect-tutorial-for-beginners/#respond Sun, 11 Oct 2020 12:16:00 +0000 https://kensoftph.com/hover-effect-in-java-programming-language-using-netbeans-ide/ Java Hover Effect

Most of the beginners want to know how the Java hover effect works. In Java programming language, we can easily do it by using those mouse events. Before we dig into that and if you find it helpful, make sure you follow this website to keep you updated on our future blog post ?. First, you need to have a component. Examples of components are the buttons, checkboxes, scrollbars, etc. Once you have a component, create a MouseEntered event. Let us assume I have JLabel with a variable name hover. See this sample code.

Java Hover

//Mouse Entered
private void hoverMouseEntered(java.awt.event.MouseEvent evt){
    hover.setText("Your cursor entered!");
}

Every time the cursor entered on the JLabel, the text will be automatically set the text whatever text you’ve set on it. Now let’s proceed on the MouseExited event.

//Mouse Exited
private void hoverMouseExited(java.awt.event.MouseEvent evt){
    hover.setText("Your cursor just exited!");
}

Hover effect in Java

Hover effect in Java

How easy is that! ? Now try it on your computer. We’re still not yet done. Let us also try the Image hover effect in Java!

Java Hover effect
 
 
//Mouse Entered hovering an icon
private void hoverMouseEntered(java.awt.event.MouseEvent evt){
    ImageIcon ii = new ImageIcon(getClass().getResource("icon2.png");
    hover.setIcon(ii);
}

and for the MouseExited ?

//Mouse Exited
private void hoverMouseExited(java.awt.event.MouseEvent evt){
    ImageIcon ii = new ImageIcon(getClass().getResource("icon1.png");
    hover.setIcon(ii);
}

That’s it! very easy right?. I hope you have learned something new! Happy coding! Watch this youtube video to see the output

 

YouTube Video

]]>
https://kensoftph.com/java-hover-effect-tutorial-for-beginners/feed/ 0 Java Tutorial: How to make hovering button in Java nonadult