skip to Main Content

I would like to have some text but have each character have more colors. Here is an example,
please ignore the eggs for o’s, those are just part of my logo. The first image was created with Photoshop and the second with Word.
enter image description here

But instead of that showing, this is shown instead:
enter image description here

This does make sense because it is a font and the font has no color in it whatsoever but I want to know if there is a way to make the text colored and shaded differently like the ‘N’ appears in TYCOON. This would be displayed in a JLabel. Any help is appreciated!

2

Answers


  1. It’s going to be pretty hard to convert text into a fancy logo… Instead use images.

    Put your text into photoshop and export it as an image (like you did). Then use the image in place of the text.

    Login or Signup to reply.
  2. First, you need to create an image for each character containing the (fancy) color you need (e.g. in PhotoShop or whatever other application you use to create images for your game).

    Next, you need to use these images to draw the texts, instead of using regular fonts and the JLabel. So that requires (slightly) more work…

    As you do not provide any details on the Java components/libraries you use, I can only provide some pseudo-code as an example:

    String text = "My colorful text";
    int x = START_X; //< x-coordinate of next char
    int y = START_y; //< y-coordinate of next char
    
    for (int i = 0; i < text.length(); i++) {
      char c = text.charAt(i));
      switch(c) {
        case ' ': //Space, increase x-coordinate
          x += SPACE_WIDTH;
          break;
         case 'n': // New line, reset x-coordinate and increase y-coordinate
           x = START_X;
           y += LINE_HEIGHT;
         default: // Draw character at x, y and increase x-coordinate
           charImage = getImage(c);
           drawCharacter(x, y, charImage);
           x += charImage.getWidth();
       }
    }
    

    This (pseudo-code) example assumes you have

    • a method that finds the correct image for a given character: getImage()
    • a method to draw the image: drawCharcter()
    • a method to find the width of an image: getWidth()

    Furthermore, you probably need some extra checks/case-statements to handle other special characters you might encounter.
    But the example should help you setup the code to tackle your problem.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search