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,525
  • 20
  • 134
  • 319
Code Hungry
  • 3,930
  • 22
  • 67
  • 95

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,246
  • 9
  • 49
  • 68