Forums Register Login

multiple lines in JEditorPane

+Pie Number of slices to send: Send
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();
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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().
+Pie Number of slices to send: Send
thank you. next question... would i be able to use this with the array, allPages, that i have defined in my above code?
+Pie Number of slices to send: Send
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();
+Pie Number of slices to send: Send
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();
Willie Smits can speak 40 languages. This tiny ad can speak only one:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2319 times.
Similar Threads
Images in User Help file
Problem writing a string into a file
displaying multiple lines of text in JTextArea
display web page
Disable selection from the JEditorPane
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 23:34:43.