When I tried to draw white letters on a black background, I noticed something strange.
public WhiteOnBlackPanel() {
setBackground(Color.BLACK);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(new Color(255,255,255));
g.drawString("Hello World",100,100);
g.drawLine(0,0,100,100);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.add(new WhiteOnBlackPanel());
frame.setTitle("Hello World");
frame.setSize(600,400);
frame.setLocation(100,100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
! Do not look at the code in the images, just look at the frame!
Give it to me:

The lines, however, are well drawn.

When I took another, but very close, color (254, 255, 255), I got this

Why is java.awt.Graphicsblocking pure white (255,255,255) letters from drawing (even if it is on a black background)?
Tia, Charlie
source
share