2012-07-13 37 views
0

我在做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); 
    }  

這是我如何改變背景顏色。如何更改按鈕的文本顏色。

在此先感謝。

回答

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

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

相關問題