Hello,
when uncommenting the "UIManager.put(...)" line in the following code
all combos display their text ungreyed when disabled. But how to proceed, if you want to give this feature only to specific combos? Setting the foreground colour, even when done in an own renderer, doesn't work.
There has been a discussion of the same problem in
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=276411
but it always comes back to the overall solution with the UIManager.
If the solution should be to write an own ComboUI, does anybody have an example, for my own attempt badly failed.
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.*;
public class TextColor extends javax.swing.JFrame {
public TextColor() {
setSize(350,300);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container cp= getContentPane();
cp.setLayout(null);
JComboBox cmb1 = new JComboBox();
cmb1.addItem("Normal");
cmb1.setBounds(100,50,100,20);
JComboBox cmb2 = new JComboBox();
cmb2.addItem("Disabled");
cmb2.setBounds(100,100,100,20);
cmb2.setEnabled(false);
cmb2.setForeground(Color.BLACK);
JTextField tf = (JTextField)cmb2.getEditor().getEditorComponent();
tf.setForeground(Color.BLACK);
cp.add(cmb1);
cp.add(cmb2);
setVisible(true);
cp.requestFocusInWindow();
}
public static void main(String arg[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
// UIManager.put("ComboBox.disabledForeground", new ColorUIResource(0,0,0));
new TextColor();
}
});
}
}