jtable上允许的最大行数

时间:2016-09-24 03:34:18

标签: jtable

有人知道jFrame中的jTable是否有显示行限制?我必须在jTable中显示9 500 000行,有人知道这是否可行?

我的代码:

private void jButton1MouseClicked(java.awt.event.MouseEvent evt){

        double prob;
        Vector row = new Vector();
        int cont=0;
        DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
        for (int i = 0; i < 2; i ++) {
            for (int j = 0; j < 4; j++){
                for (int k = 0; k < 4; k++){
                    for (int l = 0; l < 3; l++){
                        for (int m = 0; m < 4; m++){
                            for (int n = 0; n < 4; n++){
                                for (int o = 0; o < 3; o++){
                                    for (int p = 0; p < 4; p++){
                                        for (int q = 0; q < 4; q++) {
                                            for (int r = 0; r < 2; r++){
                                                for (int s = 0; s < 4; s++){
                                                    for (int t = 0; t < 4; t++){
                                                        for (int u = 0; u < 4; u++) {
                                                             prob = ((pesogabinete * retornaSimGabinete(gabinetesel,gabinete.get(i))) + (pesoprocessador *(retornaSimProc(processadorsel,processador.get(j)))) + (pesomemoria * (retornaSimMem(memoriasel,memoria.get(k)))) + (pesohd * (retornaSimHd(hdsel,hd.get(l)))) + (pesossd * (retornaSimSsd(ssdsel,ssd.get(m)))) + (pesogpu * (retornaSimGpu(gpusel,gpu.get(n)))) +  (pesoteclado * (retornaSimTeclado(tecladosel,teclado.get(o)))) + (pesomouse * (retornaSimMouse(mousesel,mouse.get(p)))) + (pesofonte * (retornaSimFonte(fontesel,fonte.get(q)))) + (pesorefrigeracao * (retornaSimRefrigeracao(refrigeracaosel,refrigeracao.get(r)))) + (pesomonitor * (retornaSimMonitor(monitorsel,monitor.get(s)))) + (pesoheadset * (retornaSimHeadset(headsetsel,headset.get(t)))) + (pesomotherboard * (retornaSimMotherboard(motherboardsel,motherboard.get(u))))) / (pesogabinete+pesoprocessador+pesomemoria+pesohd+pesossd+pesomouse+pesoteclado+pesogpu+pesofonte+pesorefrigeracao+pesomonitor+pesoheadset+pesomotherboard);
                                                             row.add(gabinete.get(i));
                                                             row.add(processador.get(j));
                                                             row.add(memoria.get(k));
                                                             row.add(hd.get(l));
                                                             row.add(ssd.get(m));
                                                             row.add(gpu.get(n));
                                                             row.add(teclado.get(o));
                                                             row.add(mouse.get(p));
                                                             row.add(fonte.get(q));
                                                             row.add(refrigeracao.get(r));
                                                             row.add(monitor.get(s));
                                                             row.add(headset.get(t));
                                                             row.add(motherboard.get(u));
                                                             row.add(Double.toString(prob));
                                                             model.addRow (row);
                                                             cont++;
                                                             System.out.println(cont);
                                                             row.clear();
                                                        }                                  
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                            }
                        }
                    }
                }
            }
        }
    }                                     


    public static void main(String args[]) {

        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Tela().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList<String> jList1;
    private javax.swing.JList<String> jList10;
    private javax.swing.JList<String> jList11;
    private javax.swing.JList<String> jList12;
    private javax.swing.JList<String> jList13;
    private javax.swing.JList<String> jList2;
    private javax.swing.JList<String> jList3;
    private javax.swing.JList<String> jList4;
    private javax.swing.JList<String> jList5;
    private javax.swing.JList<String> jList6;
    private javax.swing.JList<String> jList7;
    private javax.swing.JList<String> jList8;
    private javax.swing.JList<String> jList9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane11;
    private javax.swing.JScrollPane jScrollPane12;
    private javax.swing.JScrollPane jScrollPane13;
    private javax.swing.JScrollPane jScrollPane14;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JTextField jTextField11;
    private javax.swing.JTextField jTextField12;
    private javax.swing.JTextField jTextField13;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    // End of variables declaration                   
}

显示的错误:

at javax.swing.JTable.getValueAt(9436654
JTable.java:2717)

at javax.swing.plaf.basic.BasicTableUI.paintCell(9436681
BasicTableUI.java:2114)

at javax.swing.JComponent.paint(9436742
JComponent.java:1056)

at java.awt.EventDispatchThread.pumpEvents(9436957
EventDispatchThread.java:93)

我认为问题出现在row.clear()中,因为如果删除此代码,则代码可以正常工作,但在表格中显示的值始终相同。

1 个答案:

答案 0 :(得分:1)

事实上,我不确定这是否可行。但你可以测试一下。试试这个(尝试自己编写代码)

1-写一个特定的函数,它有一个从零到你感兴趣的大小(比如9500000)的循环。在这个循环中,将类似字符串或迭代次数的内容写入预定义的输出文件(逐行)。

2-然后在另一个函数(比如填充表)中逐行读取该文件,并将readed作为新行添加到表中。 如果可能,表格将被填充,如果没有,将发生特定的例外。

.......................................... 试试这个

在框架中添加一个完全在列上且没有行的表。

for(int i = 0; i&lt; 1000000; i ++)

{

//这里向表中添加一个新行

//如果发生错误,请减小循环的大小。

}