Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiple lines in JEditorPane

 
Charlotte Shearrill
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i would like to display multiple lines to the text area in the JEditorPane. I am comfortable with displaying one item to the text area, but how do I display multiple lines to the text area? I am new to swing. Any direction is greatly appreciated.
ResultSet rs5 = stmt5.executeQuery(SQLstmt5);
while (rs5.next()){
String operName = rs5.getString("name");
String operName_NoSpc = operName.trim();
//HtmlPane.setText(operName_NoSpc);//one item at a time
allPages[z] = operName_NoSpc;
z++;
}
rs5.close();
 
Jennifer Garrett
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you use HTML (setContentType("text/html") then you just insert some
or
between the lines and you only call setText once with all the lines and the
or
line separators.
 
Jennifer Garrett
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops, I forgot how to write > and < in html. I was trying to say insert some <p> and <br> to the text before doing setText().
 
Charlotte Shearrill
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you. next question... would i be able to use this with the array, allPages, that i have defined in my above code?
 
Jennifer Garrett
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could do something like this, since you already have a while loop. You don't need the array allPages, but if you really want to use it you can. You could loop through all the elements in the array and append them to the stringbuffer, but it might be easier to do it this way:

StringBuffer newText = new StringBuffer("");
ResultSet rs5 = stmt5.executeQuery(SQLstmt5);
while (rs5.next()){
String operName = rs5.getString("name");
String operName_NoSpc = operName.trim();
newText.append(operName_NoSpc);
// HtmlPane.setText(operName_NoSpc); //one item at a time
allPages[z] = operName_NoSpc;
z++;
}
HtmlPane.setText(newText.toString());
rs5.close();
 
Jennifer Garrett
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
StringBuffer newText = new StringBuffer("");
ResultSet rs5 = stmt5.executeQuery(SQLstmt5);
while (rs5.next()){
String operName = rs5.getString("name");
String operName_NoSpc = operName.trim();
newText.append(operName_NoSpc);
newText.append("<br>");

// HtmlPane.setText(operName_NoSpc); //one item at a time
allPages[z] = operName_NoSpc;
z++;
}
HtmlPane.setText(newText.toString());
rs5.close();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic