如何更改鼠标的字体颜色并在java中输入鼠标并退出

问题描述:

我在做Swing应用程序。我想更改上的按钮的文本颜色MouseEnteredMouseExited如何更改鼠标的字体颜色并在java中输入鼠标并退出

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); 
    }  

这是我如何改变背景颜色。如何更改按钮的文本颜色。

在此先感谢。

您可以使用Button.setForeground(Color.red);方法设置新的字体颜色。

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); 
    } 
+0

那么我的导航首先加载其他答案,很奇怪:\。 – 2012-07-13 05:53:46