GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes multiple lines in JEditorPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "multiple lines in JEditorPane" Watch "multiple lines in JEditorPane" New topic
Author

multiple lines in JEditorPane

Charlotte Shearrill
Ranch Hand

Joined: Dec 07, 2001
Posts: 34
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

Joined: Oct 31, 2001
Posts: 13
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

Joined: Oct 31, 2001
Posts: 13
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

Joined: Dec 07, 2001
Posts: 34
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

Joined: Oct 31, 2001
Posts: 13
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

Joined: Oct 31, 2001
Posts: 13
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();
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: multiple lines in JEditorPane