Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当AttributedString';s迭代器由图形对象绘制_Java_Arrays_Nsattributedstring_Graphics2d_Freeze - Fatal编程技术网

Java 当AttributedString';s迭代器由图形对象绘制

Java 当AttributedString';s迭代器由图形对象绘制,java,arrays,nsattributedstring,graphics2d,freeze,Java,Arrays,Nsattributedstring,Graphics2d,Freeze,我有一个AttributedString对象数组。我使用它们,以便可以将字符串的一部分设置为一种颜色,将字符串的其余部分设置为另一种颜色 但是,我注意到,当图形对象在attributeString.getIterator()上使用drawString()方法时,代码中的所有内容都会暂停。代码在第一个代码上停止,然后在其余代码上正常继续 我也有理由相信getIterator()方法并不是让它慢下来的原因。我尝试创建AttributedCharacterIterator数组,在其他资源加载并使用该数

我有一个AttributedString对象数组。我使用它们,以便可以将字符串的一部分设置为一种颜色,将字符串的其余部分设置为另一种颜色

但是,我注意到,当图形对象在attributeString.getIterator()上使用drawString()方法时,代码中的所有内容都会暂停。代码在第一个代码上停止,然后在其余代码上正常继续

我也有理由相信getIterator()方法并不是让它慢下来的原因。我尝试创建AttributedCharacterIterator数组,在其他资源加载并使用该数组绘制字符串时,从AttributedString数组获取迭代器

如果有帮助的话,我使用的是Mac OSX El Capitan 10.11.6,我使用的安装JRE是Java SE 8[1.8.0_65]

以下是相关代码:

private static AttributedString[] exampleList = new AttributedString[6];

// In the main method
exampleList[0] = new AttributedString("Example String Zero");
exampleList[0].addAttribute(TextAttribute.FOREGROUND, Color.BLUE, 0, 2);
exampleList[1] = new AttributedString("Example String One");
exampleList[1].addAttribute(TextAttribute.FOREGROUND, Color.BLUE, 0, 5);
exampleList[2] = new AttributedString("Example String Two");
exampleList[2].addAttribute(TextAttribute.FOREGROUND, Color.BLUE, 0, 3);
exampleList[3] = new AttributedString("Example String Three");
exampleList[3].addAttribute(TextAttribute.FOREGROUND, Color.BLUE, 0, 4);
exampleList[4] = new AttributedString("Example String Four");
exampleList[4].addAttribute(TextAttribute.FOREGROUND, Color.BLUE, 0, 5);
exampleList[5] = new AttributedString("Example String Five");
exampleList[5].addAttribute(TextAttribute.FOREGROUND, Color.BLUE, 0, 2);
for(int i = 0; i < creditNames.length; ++i)
    exampleList[i].addAttribute(TextAttribute.FONT, scoreFont);

// In the paintComponent(Graphics g) method overriden for the JPanel where everything is drawn
g2d.setColor(Color.WHITE);
g2d.setFont(scoreFont);
int y = 10;
for(AttributedString a : exampleList)
    g2d.drawString(a.getIterator(), 50, y += 50);
private static AttributedString[]exampleList=new AttributedString[6];
//主要方法
exampleList[0]=新的AttributeString(“Example String Zero”);
示例列表[0].addAttribute(TextAttribute.前台,Color.BLUE,0,2);
exampleList[1]=新的AttributeString(“示例字符串一”);
示例列表[1].addAttribute(TextAttribute.FOREGROUND,Color.BLUE,0,5);
exampleList[2]=新的AttributeString(“示例字符串二”);
示例列表[2].addAttribute(TextAttribute.FOREGROUND,Color.BLUE,0,3);
exampleList[3]=新的AttributeString(“示例字符串三”);
示例列表[3].addAttribute(TextAttribute.FOREGROUND,Color.BLUE,0,4);
exampleList[4]=新的AttributeString(“示例字符串四”);
示例列表[4].addAttribute(TextAttribute.FOREGROUND,Color.BLUE,0,5);
exampleList[5]=新的AttributeString(“示例字符串五”);
exampleList[5].addAttribute(TextAttribute.前台,Color.BLUE,0,2);
对于(int i=0;i
如果还需要什么,请告诉我