[英]How to change font color on Mouse enter and Mouse Exit in java
我正在做一個Swing應用程序。我想在MouseEntered和MouseExited上更改按鈕的文本顏色。
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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.