Java如何同时使用outline和TextAttribute编写文本

Java如何同时使用outline和TextAttribute编写文本,java,graphics,Java,Graphics,我目前正在使用这种方式: 要编写带有大纲的文本,并创建下划线、背景色等,请执行以下操作: 但是如果有大纲,它不会显示文本属性,当我选中AttributedString\getIterator().getAttributes()时,它看起来是正确的: {java.awt.font.TextAttribute(strikethrough)=true, java.awt.font.TextAttribute(foreground)=java.awt.Color[r=255,g=255,b=255],

我目前正在使用这种方式: 要编写带有大纲的文本,并创建下划线、背景色等,请执行以下操作:

但是如果有大纲,它不会显示文本属性,当我选中
AttributedString\getIterator().getAttributes()
时,它看起来是正确的:

{java.awt.font.TextAttribute(strikethrough)=true, java.awt.font.TextAttribute(foreground)=java.awt.Color[r=255,g=255,b=255], java.awt.font.TextAttribute(font)=java.awt.Font[family=Impact,name=Impact,style=bolditalic,size=80], java.awt.font.TextAttribute(underline)=0}
因此添加了属性

我也在用

createGlyphVector(<getFontRenderContext>, AttributedString#getIterator)
createGlyphVector(,AttributedString#getIterator)

使用大纲正确写入文本,但不显示属性。

而不是
font.createGlyphVector
使用
java.awt.font.TextLayout

TextLayout textlayout = new TextLayout(attributes.getIterator(), graphics.getFontRenderContext());
// the position of the shape at the graphic
Shape shape = textlayout.getOutline(AffineTransform.getTranslateInstance(xOffset, yOffset));
graphics.setColor(outlineColor);
// Choose another width / strength of the stroke on demand
graphics.setStroke(new BasicStroke(font.getSize2D() / 10.0f));
// draw the outline / stroke
graphics.draw(shape);
// draw / fill the letters / text
graphics.setColor(textColor);
graphics.fill(shape);