Pigment effect to color a MacOS X button?

I wan't to have a button that toggles between tinted green and red, without lightening its black text and normal shading effects, and I'd like to keep using the MacOS X look. But MacOS X buttons don't seem to allow changing the color of the button (setForeground colors the text, and setBackground colors the surrounding area).

New to Java programming as I am, I had the notion that I might be able to acheive this effect by overlaying the button with a green or red rectangle and displaying some kind of composite of the two.

My questions are 1) How can you get a true subtractive color (pigment) effect using composites? and 2) Would a button with a rectangle over it work anyway?

If you have any solutions or ideas, I would greatly appreciate knowing them. Showing me some code would also be very helpful. I'm just a lowly cognitive psychology grad student trying to design an experiment, and I've been giving myself a crash course in Java to get it done.

Thanks!

[1014 byte] By [Optimalista] at [2007-10-3 5:27:03]
# 1

This kind of works:

import java.awt.*;

public class ColoredButton extends Button {

public static void main(String[] argv) {

Frame f = new Frame("test");

f.add(new ColoredButton("push"));

f.pack();

f.setVisible(true);

}

public ColoredButton(String s) {

super(s);

}

public void paint(Graphics g) {

super.paint(g);

g.setColor(new Color(0xcc, 0xcc, 0xff, 0x66));

g.fillRect(0, 0, getWidth(), getHeight());

}

}

But it's an awful kluge.It's drawing a partially transparent square over the button, like you said. I'll let you judge whether it works.

You should probably ask on a Swing or AWT forum.

paulcwa at 2007-7-14 23:34:20 > top of Java-index,Java Essentials,New To Java...