Line Wrap in JTextPane

Posted on 2007-10-16
Last Modified: 2013-11-23
I have JTextPane with HTML like this

      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??
Question by:sangameshrh
    LVL 92

    Accepted Solution

    it'll already do line wrap, just set the width
    it acts just like a browser.

    though why are mixing styles with html?
    LVL 92

    Expert Comment

    its actually a RFE

    perhaps try some of the workarounds if thats what u need

    did u try using html markup to specify your styling?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now