Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6668777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:04:39+00:00 2026-05-26T03:04:39+00:00

I have come to the conclusion HTML enabled JTextPanes do not support word wrapping.

  • 0

I have come to the conclusion HTML enabled JTextPanes do not support word wrapping. So I am attempting to provide a home brew method. I will post it on the ‘net once it is complete. I may not have the greatest technique but it should work when it’s done. My problem is for some insane (very fustrating) reason when I pass an index to my substring command it switches the actual value with the same value but in negitive and throws a java.lang.StringIndexOutOfBoundsException. But when the variable is sent to the substring command it is positive for sure. When I substitute the variables for values it works fine. I would appreciate any help. I will include the soure.

    String wordWrap( String oldtxt )    {

        int ishere = 0;         // the current index
        int charlen = 0;        // The current length of the current line
        int beginint = 0;       // Where the text between tags begins
        int endint = 0;         // Where the text between tags ends
        String tempstr = "";    // Where the text is 
        String newoldtxt = "";  // to work around the damned oc error
        String newtxt = "";     // The new text being built
        String divystr = "";    // Temp variable to hold a partial string
        Boolean a = true;       // Needed as temp storage variable

        newoldtxt = oldtxt;

        while( true ) {

            endint = oldtxt.indexOf( "<", endint );

            if( endint == -1 )  {

                endint = oldtxt.length();
                a = false;
            }


            ishere = endint;
            tempstr = oldtxt.substring( beginint, endint );             // Save the text in a temp string

            while( ishere > endint )
            if( tempstr.length() > ( 22 - charlen ))  {                 // Testing for a complete line

//              newtxt += tempstr.substring( ishere, 22 - charlen );        // If a line is complete a line is printed to the pane
                newtxt += tempstr.substring( ishere, 22 );      // If a line is complete a line is printed to the pane
                ishere += 22 - charlen;                                     // Bumping the current index along
                charlen = 0;
                newtxt += "<br />";                                         // Attach a line break
                if( ishere >= tempstr.length() && a == false )
                return newtxt;

            } else if( tempstr.length() < ( 22 - charlen) )  {          // Checking to see if there are fewer then 22 chars in the string

                divystr = tempstr.substring( ishere, tempstr.length() );    // Dump the rest of the substring into the rebuilt string
                newtxt += divystr;                                          // Assign the remaining tempstr characters to newtxt
                charlen += divystr.length();                                // Add stray chars to charlen

                if( a == false )
                    return newtxt;
            }

            beginint = oldtxt.indexOf( ">", ( endint ) );                       // Locate end bracke
            newtxt += oldtxt.substring( beginint, endint );             // Add tag to newtxt
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:04:39+00:00Added an answer on May 26, 2026 at 3:04 am

    When you do the final substring call, the value of endint is 0, which is larger than the start index, resulting in a StringIndexOutOfBoundsException.

    // endint is larger than beginint here
    newtxt += oldtxt.substring( beginint, endint );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have come to the conclusion that the very nifty ASP.NET Dynamic Data framework
I have come to the conclusion that SQL Server CE isn't a viable product.
I'm struggling to get my head around LINQ and have come to the conclusion
After carrying out a lot of research I have come to the conclusion that
Let me say, I have come to the conclusion (after a lot of trial)
I have come across a lot of optimization tips which say that you should
I have come across the following type of code many a times, and I
I have come to see an Installer class item in Visual studio. Why they
I have come across what must be a common problem. When I have an
I have come across a quirky feature in Visual Studio and I was interested

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.