简体   繁体   English

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

[英]How to change font color on Mouse enter and Mouse Exit in java

I am Doing an Swing Application.I want to Change Text Color of the Buttons on MouseEntered and MouseExited . 我正在做一个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);
    }    

This is How i am Changing Background Color. 这就是我如何改变背景颜色。 How to Change Text color of the Button. 如何更改按钮的文本颜色。

Thanks in Advance. 提前致谢。

You can use the Button.setForeground(Color.red); 你可以使用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);
    }  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM