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 6136803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:38:52+00:00 2026-05-23T17:38:52+00:00

one problem I’m having is i have 2 JTextAreas and i need to add

  • 0

one problem I’m having is i have 2 JTextAreas and i need to add a list of items to them.
The problem I’m running into is the string doesn’t automatically move to the next line when it reaches the end of the JTextArea. So to solve this problem I tried this: (sorry if my code is kinda sloppy.)

public void setIncludeAndExclude(ArrayList<JComboBox> boxes){
    String in = "",ex = "";
    String[] inSplit, exSplit;


    boolean[] include = new boolean[boxes.get(0).getModel().getSize()-1];
    for(int i = 0; i < boxes.size(); i ++){
        if(boxes.get(i).getSelectedIndex() != 0){
            include[boxes.get(i).getSelectedIndex() -1] = true;
        }
    }

    for(int i = 0; i < include.length; i ++){
        if(include[i]){
            //numToItem is a method that turns an int into a string e.g. 1 = "Acesss Doors"
            in += (numToItem(i+1)+ ", ");
        }else{
            ex += (numToItem(i+1)+ ", ");
        }
    }

    //take off the last comma
    in = in.substring(0,in.lastIndexOf(","));
    ex = ex.substring(0,ex.lastIndexOf(","));

    //get how many lines there should be        
    inSplit = new String[(in.length()/100) +1];
    exSplit = new String[(ex.length()/100) +1];

    String temp;        
    int istart = 0, iend = Math.min(100, in.length()), estart = 0, eend = Math.min(100, ex.length());

    for(int i = 0; i < inSplit.length; i ++){
        try{
            temp = in.substring(istart, iend);
            int Iindex = temp.lastIndexOf(",");
            temp = ex.substring(estart, eend);
            int Eindex = temp.lastIndexOf(",");
            inSplit[i] = in.substring(istart, Iindex);
            exSplit[i] = ex.substring(estart, Eindex);
            istart = Iindex; iend = Math.min(iend + 100, in.length());
            estart = Eindex; eend = Math.min(eend + 100, ex.length());
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    //reset in and ex to ""     
    in = ""; ex = "";

    //set in and ex to the new string with newline characters
    for(int i = 0; i < inSplit.length; i ++){
        in += inSplit[i] + "\n";
        ex += exSplit[i] + "\n";
    }

    //set the text of the JTextAreas
    Include.setText(in);
    Exclude.setText(ex);

}

any help on what i could do different or change would be much appreciated

  • 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-23T17:38:53+00:00Added an answer on May 23, 2026 at 5:38 pm

    JTextArea has setLineWrap(...) and the setWrapStyleWord(...) methods. Perhaps all you need to do is call these on your JTextArea‘s setting both to true.

    One bit of criticism: your code is very hard to interpret as you give no indication which variables are JTextAreas (which I’m guessing are “Include” and “Exclude”), and no comments as to what is doing what. Please write your questions here with the idea that we know nothing about your code and can’t read minds. The clearer your question, usually the easier it is to answer. Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one problem. i have dep. prop. of type List.. public const string
I am facing one problem from last one week. I have one list having
I have one problem HashMap<String, List<AppPrjMilestone>> dateMilestoneMap = new HashMap<String, List<AppPrjMilestone>>(); I am putting
One problem that I have frequently run into lately is the problem of my
have one problem, I need the dates in Swedish format, for instance, october is
i 'mstuck in one problem Drag-able list items.... i want to arrange my list
One problem that I have with emacs is that it doesn't seem to handle
I have one problem with two sections in UITableview grouped style. First section having
One problem I have with open-source is not often the product or documentation, but
One problem that I come across regularly and yet don't have a solution to

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.