使用透明部分绘制字符时,您可以看到透过的背景颜色。如何将字体透明部分更改为白色?
package com.gmail.vstollen;
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);
}
}
我该怎样做才能让它像this一样?