I am having issues while trying to make a highlighting 'label' that changes its icon, okay, so when MouseEntered event is being called for one jLabel, every nearby label's event is also being called and their icon is being changed. I've tried to disable that by using variable to deny changing other jLabel icons but it remains the same like it's being called at the same moment without letting the program storing values in variable and performing if checks, here's the code:
private int OverlayButton = -1;
private void jLabel1MouseEntered(java.awt.event.MouseEvent evt) {
SetButton( 1 );
}
private void jLabel1MouseExited(java.awt.event.MouseEvent evt) {
ResetButton( 1 );
}
private void jLabel2MouseEntered(java.awt.event.MouseEvent evt) {
SetButton( 2 );
}
private void jLabel2MouseExited(java.awt.event.MouseEvent evt) {
ResetButton( 2 );
}
private void jLabel3MouseEntered(java.awt.event.MouseEvent evt) {
SetButton( 3 );
}
private void jLabel3MouseExited(java.awt.event.MouseEvent evt) {
ResetButton( 3 );
}
public void SetButton( int button ) {
if( OverlayButton == -1 ) {
OverlayButton = button;
System.out.println( "SetButton method | (BUTTON-ID:"+ button+ ") ." );
switch( button ) {
case 1: {
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Agendicus/SecondaryCalendar.png")));
}
case 2: {
jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Agendicus/SecondaryNotification.png")));
}
case 3: {
jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Agendicus/medal (1).png")));
}
case 4: {
}
}
}
else {}
}
public void ResetButton( int button ) {
if( OverlayButton != -1 ) {
switch( button ) {
case 1: {
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Agendicus/calendar-with-a-clock-time-tools.png")));
}
case 2: {
jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Agendicus/notifications-button.png")));
}
case 3: {
jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Agendicus/medal (2).png")));
}
}
System.out.println( "ResetButton method | (BUTTON-ID:"+ button+ ") | Setting OverlayButton to -1." );
OverlayButton = -1;
}
}
I've also tried using resetting icons under each event for different jLabels, but unsuccessfuly.