> Hello,
>
> I am trying to control some Look & Feel Color parameters for the JCheckBox
> class. I am using Java 1.3.1
<snippage>
Here's how I did it (I had to override the default, because I had
dark-background JPanels, and the default 'tick' doesn't show up on those):
in init(),main() or wherever you initialise the GUI:
....
UIManager.put("CheckBox.icon", new MyCheckIcon()); //black tick on dark
background = bad
....
and the MyCheckIcon class is:
import javax.swing.plaf.metal.*;
import javax.swing.*;
import java.awt.*;
public class MyCheckIcon extends MetalCheckBoxIcon{
protected void drawCheck(Component c, Graphics g, int x, int y) {
Color old = g.getColor();
g.setColor(DomCalculator.tickColor); // see note
int controlSize = getControlSize();
g.fillRect( x+3, y+5, 2, controlSize-8 );
g.drawLine( x+(controlSize-4), y+3, x+5, y+(controlSize-6) );
g.drawLine( x+(controlSize-4), y+4, x+5, y+(controlSize-5) );
g.setColor(old);
}
}
/* DomCalculator.tickColor for my project was a public static data field ...
replace with whatever colour tick you want.
Also, if you're using a different LAF, replace the metal import/name by the
proper ones for your LAF */
Jim Crowell - 05 Nov 2003 14:12 GMT
Simon,
> Here's how I did it (I had to override the default, because I had
> dark-background JPanels, and the default 'tick' doesn't show up on those):
[quoted text clipped - 5 lines]
> background = bad
> ....
My problem is that somehow my UIManager.put("CheckBox.icon", ... operation
is not being registered OR the registration is being corrupted somewhere.
When I received this response I added a System.out.println statement to my
'drawCheck' Method also but I never get there.
Look like from your response and other examples I found on the Intrernet
that I am doing what I should be doing but something in my code is messing
up the UIManager processing.
Thanks,
Jim