0

以下是我尝试对 Jtable 执行少量添加列和添加行时遇到的异常。

哪位大神帮忙看看!!

Exception in thread "AWT-EventQueue-3" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
    at java.util.Vector.elementAt(Vector.java:447)
    at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:650)
    at javax.swing.JTable.getValueAt(JTable.java:2715)
    at javax.swing.JTable.prepareRenderer(JTable.java:5715)
    at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2108)
    at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:2010)
    at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1806)
    at javax.swing.plaf.ComponentUI.update(ComponentUI.java:161)
    at javax.swing.JComponent.paintComponent(JComponent.java:765)
    at javax.swing.JComponent.paint(JComponent.java:1029)
    at javax.swing.JComponent.paintChildren(JComponent.java:866)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JViewport.paint(JViewport.java:764)
    at javax.swing.JComponent.paintChildren(JComponent.java:866)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JComponent.paintChildren(JComponent.java:866)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JComponent.paintChildren(JComponent.java:866)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JLayeredPane.paint(JLayeredPane.java:581)
    at javax.swing.JComponent.paintChildren(JComponent.java:866)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JComponent.paintChildren(JComponent.java:866)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JComponent.paintChildren(JComponent.java:866)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JLayeredPane.paint(JLayeredPane.java:581)
    at javax.swing.JComponent.paintToOffscreen(JComponent.java:5138)
    at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:302)
    at javax.swing.RepaintManager.paint(RepaintManager.java:1216)
    at javax.swing.JComponent._paintImmediately(JComponent.java:5086)
    at javax.swing.JComponent.paintImmediately(JComponent.java:4896)
    at javax.swing.RepaintManager$3.run(RepaintManager.java:807)
    at javax.swing.RepaintManager$3.run(RepaintManager.java:795)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:108)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:795)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:764)
    at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:706)
    at javax.swing.RepaintManager.access$1000(RepaintManager.java:61)
    at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1621)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:226)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:673)
    at java.awt.EventQueue.access$300(EventQueue.java:96)
    at java.awt.EventQueue$2.run(EventQueue.java:634)
    at java.awt.EventQueue$2.run(EventQueue.java:632)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:108)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:643)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)

干杯,阿吉斯

@Kleopatra

        for(int i=0;i<local.length;i++){
            //
            String funcVar = local[i][local[i].length-1];
            ArrayList<String> al = loadParametersIntoAL(funcVar);

            // fill the sort variables along with the function column
            for(int k=0;k<processInputInfo.getAsciiInitEstimates().getFuncArray().get(funcVar).size();k++){

                String[] rowData = new String[local[0].length + 4];
                for(int j=0;j<local[0].length;j++){
                    rowData[j] = local[i][j]; 
                }

                // fill the parameter name
                if(index == (al.size())){
                    index = 0;
                }
                rowData[local[0].length] =  al.get(index++);

                rowData[local[0].length +1] = "";
                rowData[local[0].length +2] = "";
                rowData[local[0].length +3] = "";

                ((DefaultTableModel)AsciiInitialEstGui.createAsciiinitGuiInst().asciiIntEstTable.getModel()).addRow(rowData);

            }

        }
4

1 回答 1

0

将您的代码放在下面的模板中:

SwingUtilities.invokeLater(new Runnable()
{
    public void run(){
        // your code here
    }
});
于 2015-11-18T16:09:09.447 回答