0

Hi iam trying to do some program that allowed me to change my font color so if i have used a check box but the problem is the combination of the color . can i combine two colors to make it the color of my font ?

Font font = new Font("Arial", Font.BOLD, 12);
                field.setFont(font);
                field.setForeground(Color.YELLOW);

// can i make this `field.setForeground(Color.YELLOW&&GREEN); //or any who else idea for combination of font colors . please help .

Batusai
  • 149
  • 1
  • 1
  • 12

1 Answers1

1

UPDATE - it seems there is a way :-)

https://github.com/benjholla/ColorMixer (does not seem to be working 100%, see the disclaimer)

see Adding Colours (Colors) Together like Paint (Blue + Yellow = Green, etc)

import java.awt.Color;
import java.awt.Font;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JLabel;

import colormixer.KMColorUtils;

public class Byta {

    public static void main(String[] args) throws IOException {
        Font font = new Font("Arial", Font.BOLD, 12);

        JFrame frame = new JFrame("HelloWorldSwing");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JLabel label = new JLabel("Hello World");
        label.setFont(font);

        Color customColor = KMColorUtils.mix(Color.CYAN, Color.YELLOW);
        label.setForeground(customColor);

        frame.getContentPane().add(label);

        frame.pack();
        frame.setVisible(true);
    }

}

gives

enter image description here

Community
  • 1
  • 1
Leo
  • 6,480
  • 4
  • 37
  • 52
  • how can i add sir ? what is (10,10,225); ? – Batusai Feb 15 '14 at 09:39
  • that's why I've posted the link in the end. There isn't such a thing as "blue + yellow = green" mathematically. There are several color models and each one gives you a different color for color add and subtraction. Please take a look on the link – Leo Feb 15 '14 at 09:42
  • i will change my code sir . because i like to mix my color if my checkbox check 2 colors because i have 3 colors yellow green white so if i check white my font color is white but if i check 2 colors i need to mix it like i check green and yellow so i need to color of my font yellow green . – Batusai Feb 15 '14 at 09:42
  • sorry, but yellow green = font with yellow and green stripes? RGB is a color model. You can somewhat convert from this color model to another like CMYK, HSV, etc. See http://en.wikipedia.org/wiki/Color_space. Java default is RGB (so 10,10,225 = Red 10, Green 10, Blue 255) - values range from 0 to 255 (max) – Leo Feb 15 '14 at 09:51
  • I am sorry, I think I've found it – Leo Feb 15 '14 at 09:54
  • i see sir last question sir . how can i concatinate this if i have checkbox ? like i check the two and it need to be Yellow green because the if(Source == check1 && Source == check2) { code here } is not working :3 . – Batusai Feb 15 '14 at 09:57
  • Please see the edited answer. But notice that adding blue and green is not the same for cyan and green (at least for this library). – Leo Feb 15 '14 at 10:04
  • its all fix sir . hehehe do you have a color brown ? combination sir ? – Batusai Feb 15 '14 at 10:06
  • muddy brown sir the combination of red and green . – Batusai Feb 15 '14 at 10:12
  • do you have a brown sir ? – Batusai Feb 15 '14 at 10:18
  • Color customColor = KMColorUtils.mix(Color.RED, Color.GREEN); does not look like a muddy brown :-( [but the library assumes equal concentrations for each color, which is wrong). Hard question, huh? – Leo Feb 15 '14 at 10:20
  • I give up :-) it seems that https://github.com/benjholla/ColorMixer still needs work. Someone at suggested to port a library of http://krita.org/download to java at http://stackoverflow.com/questions/10254022/implementing-kubelka-munk-like-krita-to-mix-colours-color-like-paint . I am sorry. I won't go further with this. – Leo Feb 15 '14 at 10:31