我试图将formattedText1的输出放入一个新列。 当前格式化的文本和formattedText1出现在一个连续列表中。我试过把+" " +在formattedText和formattedText1之间,但是没有办法,我会很感激帮助
null, (formattedText) + (formattedText1), "Cashout Prices",
以下完整代码
package simpledialogbox;
import javax.swing.JOptionPane;
import java.io.IOException;
import java.util.logging.*;
import org.jsoup.*;
import org.jsoup.nodes.*;
import org.jsoup.select.*;
public class SimpleDialogBox {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
try {
String url = "http://bmreports.com/bsp/additional/soapfunctions.php?element=SYSPRICE&dT=2014-10-03";
Document doc = Jsoup.connect(url).get();
Elements SSPparagraphs;
Elements SBPparagraphs;
SSPparagraphs = doc.select("SSP");
SBPparagraphs = doc.select("SBP");
String[] numbers = SSPparagraphs.text().toString().split(" ");
String[] numbers1 = SBPparagraphs.text().toString().split(" ");
String formattedText = new String("");
String formattedText1 = new String("");
for (int x = 0; x < numbers.length; x++)
{
formattedText += numbers[x] + "\n";
}
for (int x = 0; x < numbers1.length; x++)
{
formattedText1 += numbers1[x] + "\n";
}
JOptionPane.showMessageDialog(
null, (formattedText) + (formattedText1), "Cashout Prices", JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}
catch (IOException ex) {
Logger.getLogger(SimpleDialogBox.class.getName())
.log(Level.SEVERE, null, ex);
}
}
}
答案 0 :(得分:1)
您可以使用HTML
(我修改了这个以说明你的两栏)
(注意:您在JFrame中使用JScrollPane可以获得更好的结果)
试试这个:
String[] numbers = SSPparagraphs.text().toString().split(" ");
String[] numbers1 = SBPparagraphs.text().toString().split(" ");
//generate table and column heads
String formattedText = new String("<html><table><tbody>");
formattedText += "<tr><th>SSP</th><th>SBP</th></tr>";
//populate table with data in two columns
//will account for differing amounts of data between SBP and SSP
int x = 0;
while (x < numbers.length || x < numbers1.length)
{
formattedText += "<tr><td>";
if (x < numbers.length)
{
formattedText += numbers[x];
}
else
{
formattedText += " ";
}
formattedText += "</td><td>";
if (x < numbers1.length)
{
formattedText += numbers1[x];
}
else
{
formattedText += " ";
}
formattedText += "</td></tr>";
x++;
}
formattedText += "<tbody></table>";