Java 使用JOptionPane显示容纳的阵列

Java 使用JOptionPane显示容纳的阵列,java,arrays,swing,joptionpane,Java,Arrays,Swing,Joptionpane,我有这个代码,它运行得很好。问题是,当我尝试使用showMessageDialog显示它时,它会以一种混乱的方式显示所有内容。有没有关于如何正确显示的建议?谢谢 String tablaColeccion; tablaColeccion =""; for (int i = 0; i < informeMatrices.getVector().length; i++){ if (informeMatrices.getVector()[i] != null){ tabl

我有这个代码,它运行得很好。问题是,当我尝试使用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);
String tablaColeccion;
tablaColeccion=“”;
for(int i=0;i

我想将其显示为单独的列。任何帮助都会很棒。

我找到了这个方法。它非常简单,易于实现。只需简单地使用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);
StringBuilder sb=新的StringBuilder(128);
某人加上(“”);
for(int i=0;i
“有关于如何正确显示的建议吗?”在选项窗格中显示列表(1D数组)或表格(2D数组)。如果用户永远不需要复制数据,HTML是可以的(尤其是表格数据)。如果是这样的话,
JList
JTable
就很方便了,但是该表也可以轻松地进行排序和筛选。