使用drawString()java时会跳过Color.White(Color.White is getting skipped when using drawString() java)

编程入门 行业动态 更新时间:2024-10-28 18:34:45
使用drawString()java时会跳过Color.White(Color.White is getting skipped when using drawString() java)

当我试图在黑色背景上画白色字母时,我注意到一些奇怪的东西。

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); // The frame is visible from now on }

不要看图像中的代码,只看框架!

给我这个:

然而,线条画得很好。

当我采用不同但非常接近的颜色(254,255,255)时,我得到了这个

为什么java.awt.Graphics阻止绘制纯白色(255,255,255)字母(即使它是在黑色背景上)?

蒂亚,查理

When I was trying to draw white letters on a black background I noticed something weird.

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); // The frame is visible from now on }

! Don't look at the code in the images, just look at the frame !

Gave me this:

Lines, however, were being drawn well.

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

Why is java.awt.Graphics blocking pure white (255,255,255) letters from being drawn (even when it is on a black background) ?

Tia, Charlie

最满意答案

jdk1.8.0_20中的一个错误,至少在Linux(Ubuntu)中:0xFFFFFFFF显示为BLACK。 更改alpha或其中一个RGB值会导致“几乎为白色”。

jdk1.7.0_67在同一系统上运行正常。

检查所有形式的setColor。

后来发现bug报告: JDK-8054638:没有涂上白色

受影响的版本:8u11,8u25

这个bug只影响Linux; 在Windows上一切正常。

A bug in jdk1.8.0_20, at least in Linux (Ubuntu): 0xFFFFFFFF appears as BLACK. Changing alpha or one of the RGB values results in "almost white".

jdk1.7.0_67 works fine on the same system.

Checked all forms of setColor.

Later Found that bug is reported: JDK-8054638 : White color is not painted

Affected Versions: 8u11,8u25

This bug only affects Linux; on Windows everything works fine.

更多推荐

本文发布于:2023-08-05 09:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1431272.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时会   跳过   java   drawString   White

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!