0

我正在做一个 Swing 应用程序。我想更改MouseEnteredMouseExited上按钮的文本颜色。

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

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

提前致谢。

4

1 回答 1

2

您可以使用该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);
    }  
于 2012-07-13T05:50:01.817 回答