我有这段代码,它运行得很好。问题是,当我尝试使用 showMessageDialog 显示它时,它以困惑的方式显示所有内容。关于如何正确显示它有什么建议吗?谢谢。
String tablaColeccion;
tablaColeccion ="";
for (int i = 0; i < informeMatrices.getVector().length; i++){
if (informeMatrices.getVector()[i] != null){
tablaColeccion += informeMatrices.getVector()[i] + " ";
}
}
tablaColeccion += "\n";
for (int i = 0; i < informeMatrices.getMatriz().length; i++) {
for(int u = 0; u < informeMatrices.getMatriz().length; u++){
if (informeMatrices.getMatriz()[i][u] != null){
tablaColeccion += informeMatrices.getMatriz()[i][u] + " ";
}
}
tablaColeccion += "\n";
}
tablaColeccion += "\n\n";
JOptionPane.showMessageDialog(null,tablaColeccion,"Coleccion Completa", JOptionPane.INFORMATION_MESSAGE);
我想将其显示为单独的列。任何帮助都会很棒。
最佳答案
我找到了这种方法。它非常简单且易于实现。只需使用 HTML,即可将所有内容容纳到列和行中。
StringBuilder sb = new StringBuilder( 128);
sb.append("<html><table><tr>");
for (int i = 0; i < informeMatrices.getVector().length; i++)
{
if (informeMatrices.getVector()[i] != null)
{
sb.append("<td>" + informeMatrices.getVector()[i] + "</td>");
}
}
for (int i = 0; i < informeMatrices.getMatriz().length; i++)
{
sb.append("<tr>");
for(int u = 0; u < informeMatrices.getMatriz().length; u++)
{
if (informeMatrices.getMatriz()[i][u] != null)
{
sb.append("<td>").append(informeMatrices.getMatriz()[i][u]).append("</td>");
}
}
sb.append("</tr>");
}
sb.append("</table></html>");
JOptionPane.showMessageDialog(null,sb.toString(),"Coleccion Completa",
JOptionPane.INFORMATION_MESSAGE);
关于java - 使用 JOptionPane 显示容纳的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26227804/