2

When drawing characters with transparent parts, you can see the background color shining through. How can I change the fonts transparent parts to be white?

For example using this code, I get a chess pawn with gray background:

package org.some.package;

import javax.swing.*;
import java.awt.*;

public class Example extends JPanel {

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

        g.setColor(Color.GRAY);
        g.fillRect(0 ,0, getWidth(), getHeight());
       
        //Font containing chess figures
        g.setFont(new Font("DejaVu Sans", Font.PLAIN, 100));

        g.setColor(Color.BLACK);
        g.drawString("\u2659", 10, 100);
    }

    public static void main(String args[]) {
        JFrame frame = new JFrame("Example");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(200, 200);
        frame.add(new Example());
        frame.setVisible(true);
    }
}

What can I do to get it like this?

vstollen
  • 151
  • 1
  • 11

2 Answers2

2

I don't think it is possible with plain String drawings because of various reasons. The easiest solution would be to use Images instead of Strings; though if you really want to use Strings, you can also change the text color itself to identify a teamColor (Whichever you fancy).

n247s
  • 1,898
  • 1
  • 12
  • 30
0

Just make an image of the picture you want and draw it to 10, 100.