【问题标题】:How to change font color on Mouse enter and Mouse Exit in java如何在java中更改鼠标进入和鼠标退出的字体颜色
【发布时间】:2012-07-12 23:17:06
【问题描述】:

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

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

提前致谢。

【问题讨论】:

    标签: java swing mouseover jbutton


    【解决方案1】:

    您可以使用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);
        }  
    

    【讨论】:

    • 好吧,我的导航器先加载了另一个答案,很奇怪:\.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-09
    相关资源
    最近更新 更多