Line Wrap in JTextPane

I have JTextPane with HTML like this

pane.setContentType("text/html");
try
{
      StyledDocument doc = (StyledDocument)pane.getDocument();
      Style style = doc.addStyle("StyleName", null);
      
      StyleConstants.setFontFamily(style, "Palatino Linotype");
      StyleConstants.setFontSize(style, 15);
      StyleConstants.setForeground(style, Color.RED);
      doc.insertString(doc.getLength(), "Test fjkd sdfhsdjfhds hdsifh dsjifh hdfsjidhfjid shshfsdhf hfishf h", style);
      
      StyleConstants.setForeground(style, Color.BLACK);
      doc.insertString(doc.getLength(), "Test ", style);
      
      StyleConstants.setForeground(style, Color.BLUE);
      doc.insertString(doc.getLength(), "Test ", style);
      
      StyleConstants.setForeground(style, Color.GREEN);
      doc.insertString(doc.getLength(), "Test ", style);
      
      StyleConstants.setForeground(style, Color.YELLOW);
      doc.insertString(doc.getLength(), "Test ", style);
      
      StyleConstants.setForeground(style, Color.GRAY);
      doc.insertString(doc.getLength(), "Test ", style);
      
      StyleConstants.setForeground(style, Color.CYAN);
      doc.insertString(doc.getLength(), "Test ", style);
      
      StyleConstants.setForeground(style, Color.MAGENTA);
      doc.insertString(doc.getLength(), "Test ", style);
      
      StyleConstants.setForeground(style, Color.ORANGE);
      doc.insertString(doc.getLength(), "Test ", style);
      
      StyleConstants.setForeground(style, Color.PINK);
      doc.insertString(doc.getLength(), "Test ", style);
}
catch(Exception e)
{
}

How can DO LineWrap for this??
sangameshrhAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
it'll already do line wrap, just set the width
it acts just like a browser.

though why are mixing styles with html?
0
 
objectsCommented:
its actually a RFE

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4131119

perhaps try some of the workarounds if thats what u need

did u try using html markup to specify your styling?
0
All Courses

From novice to tech pro — start learning today.