I have a user interface for specific buttons implemented by subclassing MetalButtonUI. Buttons use shortcuts in HTML format. This is a requirement for me, I need to support multi-line button shortcuts.
For some reason, when my application runs on Java 7 (scientifically updated 4, the most current one), the text color with the button disabled is now gray. This does not happen when working on Java 4 or 6.
In HTML for a button label, I can set the font color with. <font color=..>However, this value is ignored when the button is disabled. It seems that somewhere my font color is being redefined when the button is disabled. Use is <body style='color: ..'>also inefficient.
I tried setting Button.disabledText to UIDefaults. This is not what I really want to do, because it affects too many buttons. But in any case, it is not effective for HTML button shortcuts.
MetalButtonUI defines getDisabledTextColor, but its implementation is inefficient.
Similarly, the implementation of the paintText method is inefficient. It is not called for shortcuts in HTML format.
I could override the entire drawing method, but this seems like a too complicated solution.
A patch was fixed in this area, the bug was reportedly fixed in Java 7, see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4783068 The error report is not very clear to me, however. It is unclear what exactly was changed, or how to reverse the new behavior.
Does anyone know how to control text color for disabled buttons?
EDIT: , get-go. paint() . , , button.setForeground(Color.black); Java 6 . Java 7 . mKorbel... !!!!
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class DisabledButtonDemo {
public DisabledButtonDemo() {
final JToggleButton button = new JToggleButton(
"<html><center>Button<br/>Label</center></html>");
button.setForeground(Color.black);
button.setPreferredSize(new Dimension(100, 100));
final JButton controlButton = new JButton(
"Toggle Enabled/Disabled");
controlButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button.setEnabled(!button.isEnabled());
}
});
JFrame f = new JFrame("ButtonTest");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new GridLayout(2,1));
f.add(button);
f.add(controlButton);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
DisabledButtonDemo t = new DisabledButtonDemo();
}
});
}
}
№2: Oracle, . http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7176683