JTextArea Java Multilingual Help

One problem I am facing is that I have 2 JTextAreas and I need to add a list of elements for them. The problem I am facing is a line that does not automatically go to the next line when it reaches the end of the JTextArea. Therefore, to solve this problem, I tried this: (sorry if my code is a bit messy.)

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 eg 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 differently or change would be greatly appreciated

+6
source share
2 answers

JTextArea has the methods setLineWrap(...) and setWrapStyleWord(...) . Perhaps all you have to do is call them in the JTextArea setting as true.

One bit of criticism: your code is very difficult to interpret since you are not specifying which variables are JTextAreas (which I assume are "Include" and "Exclude"), and no comments on what it does. Please write your questions here with the idea that we do not know anything about your code and cannot read thoughts. The clearer your question, the easier it is to answer. Thanks.

+7
source

Perhaps the best solution is to use JList. See How to use lists .

The code you sent is not complete. If you still want to use a text area solution, send an SSCCE message that demonstrates the problem.

+3
source

Source: https://habr.com/ru/post/892845/


All Articles