【发布时间】:2009-03-02 12:58:03
【问题描述】:
我正在研究如何“绘画” Graphics2D 上的一些属性文本。
所以,我很感兴趣是否可以保存 某种格式的 AttributedString 的内容?
我知道它可以被 Java 序列化, 但是,我在这里不需要那个解决方案。
另外,如果有人知道一些例子 如何编辑属性字符串?
这里是一些 Java 代码,只是为了了解一下:
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
AttributedString as new AttributedString( "Lorem ipsum dolor sit amet..." );
Font font1 = new Font( "SansSerif" , Font.PLAIN , 20 );
as.addAttribute( TextAttribute.FONT , font1 );
as.addAttribute( TextAttribute.FOREGROUND , Color.black );
as.addAttribute( TextAttribute.FOREGROUND , Color.blue , 4 , 9 );
AttributedCharacterIterator aci = as.getIterator();
FontRenderContext frc = g2.getFontRenderContext();
LineBreakMeasurer lbm = new LineBreakMeasurer( aci , frc );
TextLayout textLayout = lbm.nextLayout( wrappingWidth );
int x = 50 , y = 50 ;
textLayout.draw( g2 , x , y );
}
感谢任何帮助或建议:)
【问题讨论】: