0

I am Doing an Swing Application.I want to Change Text Color of the Buttons on MouseEntered and MouseExited.

private void jButton2MouseEntered(java.awt.event.MouseEvent evt) {                                      
      this.jButton2.setBackground(Color.red); 
    }                                     
    private void jButton2MouseExited(java.awt.event.MouseEvent evt) {                                     
       this.jButton2.setBackground(Color.lightGray);
    }    

This is How i am Changing Background Color. How to Change Text color of the Button.

Thanks in Advance.

mKorbel
  • 109,107
  • 18
  • 130
  • 305
Code Hungry
  • 3,750
  • 22
  • 64
  • 92

1 Answers1

2

You can use the Button.setForeground(Color.red); method to set a new font color.

private void jButton2MouseEntered(java.awt.event.MouseEvent evt) {                                      
      this.jButton2.setBackground(Color.red); 
      this.Button.setForeground(Color.red);
    }                                     
    private void jButton2MouseExited(java.awt.event.MouseEvent evt) {                                     
       this.jButton2.setBackground(Color.lightGray);
       this.Button.setForeground(Color.lightGray);
    }  
vikiiii
  • 9,092
  • 9
  • 46
  • 68