Button: disabled text

This commit is contained in:
Karl Tauber
2019-08-20 11:33:13 +02:00
parent 8ba5c9a39c
commit 2ef440a016
4 changed files with 24 additions and 0 deletions

View File

@@ -16,11 +16,16 @@
package com.formdev.flatlaf.ui;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.AbstractButton;
import javax.swing.JComponent;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicButtonUI;
import sun.swing.SwingUtilities2;
/**
* Provides the Flat LaF UI delegate for {@link javax.swing.JButton}.
@@ -62,4 +67,20 @@ public class FlatButtonUI
paint( g, c );
}
@Override
protected void paintText( Graphics g, JComponent c, Rectangle textRect, String text ) {
AbstractButton b = (AbstractButton) c;
if( b.getModel().isEnabled() )
super.paintText( g, c, textRect, text );
else {
// paint disabled text
FontMetrics fm = SwingUtilities2.getFontMetrics( c, g );
int mnemonicIndex = b.getDisplayedMnemonicIndex();
g.setColor( UIManager.getColor( "Button.disabledText" ) );
SwingUtilities2.drawStringUnderlineCharAt( c, g, text, mnemonicIndex,
textRect.x + getTextShiftOffset(),
textRect.y + fm.getAscent() + getTextShiftOffset() );
}
}
}

View File

@@ -45,6 +45,7 @@ window=@background
#---- Button ----
Button.background=4c5052
Button.disabledText=777777
Button.startBorderColor=5e6060
Button.endBorderColor=5e6060

View File

@@ -45,6 +45,7 @@ window=@background
#---- Button ----
Button.background=ffffff
Button.disabledText=999999
Button.startBorderColor=bfbfbf
Button.endBorderColor=b3b3b3

View File

@@ -23,6 +23,7 @@
#---- Button ----
Button.background=ffffff
Button.disabledText=000088
Button.startBorderColor=ff0000
Button.endBorderColor=0000ff