1

我有一个JComponent绘制多行属性的字符串,Textlayout它运行得很好:

public static float drawMultiAttributedString(Graphics2D g2d, AttributedString str, String plainString, int maxWidth, int startX, float startY){

    FontRenderContext fontRenderCtx = g2d.getFontRenderContext();

    AttributedCharacterIterator attrCharIter = str.getIterator();
    LineBreakMeasurer lineBreakMeasurer = new LineBreakMeasurer(attrCharIter, fontRenderCtx);
    float x = startX;
    float y = startY;

    int next; 
    int limit; //länge bis zum nächsten umbruch
    int charat; 
    String tested = plainString;

    while (lineBreakMeasurer.getPosition() < attrCharIter.getEndIndex()) { 

          next = lineBreakMeasurer.nextOffset(maxWidth);
          limit = next;
          charat = tested.indexOf("\n", lineBreakMeasurer.getPosition()+1);
          if(next > (charat - lineBreakMeasurer.getPosition()) && charat != -1){
             limit = charat - lineBreakMeasurer.getPosition();
          }
          TextLayout layout = lineBreakMeasurer.nextLayout(maxWidth, lineBreakMeasurer.getPosition() + limit, false);

              y += layout.getAscent(); //höhe des haupttextes

          layout.draw(g2d, x, y);

          y += layout.getDescent() + layout.getLeading(); 
    }

    return y - startY;
}

问题是,它Textlayout不会呈现我需要的制表符。有谁知道我如何包括制表符?有任何想法吗?

非常感谢!

4

1 回答 1

1

带有一个或多个自定义渲染器的 AJTable可能是更简单的选择。DefaultTableCellRendererextends JLabel,它允许HTML和特定于语言环境的格式

于 2012-08-03T20:47:48.190 回答