Java jtextarea multiline help
•
Java
One problem I encounter is that I have two jtext areas, and I need to add a project list for them
public void setIncludeAndExclude(ArrayList<JCombo@R_853_2419@> @R_853_2419@es){ String in = "",ex = ""; String[] inSplit,exSplit; boolean[] include = new boolean[@R_853_2419@es.get(0).getModel().getSize()-1]; for(int i = 0; i < @R_853_2419@es.size(); i ++){ if(@R_853_2419@es.get(i).getSelectedIndex() != 0){ include[@R_853_2419@es.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 I can make a difference or change will be appreciated
Solution
Jtextarea has setlinewrap (...) and setwrapstyleword (...) methods Maybe all you need to do is set them to true in the jtextarea settings
One criticism: your code is hard to explain because you don't specify which variables are jtextareas (I guess "include" and "exclude"), and don't comment on what is done Please write down your question here. Our idea is that we know nothing about your code and can't read it The clearer your question, the easier it is usually to answer thank you.
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码