2015-10-15 69 views
-1

我已經創建了一個包含一個JTable,當我嘗試一個DefaultTableModel分配給它一個JDialog一個DefaultTableModel向JTable,它給了我一個異常和的JDialog也不出現。 java.lang.ArrayIndexOutOfBoundsException: 11無法設置包含在一個JDialog

代碼分配表型號:

jTable1.setModel(new BomModel(GetBomForSetupMaterial.getPartPositionList())); 

AbstractTableModel類:

public class BomModel extends AbstractTableModel { 

    private static List<JPartPosition> partPositionList = new ArrayList<JPartPosition>(); 

    private String[] columnNames = {"Part Header ID", "Mounting Place", "Part Number", 
     "Component Type", "Description", "PCB Layer ID", " Processing Type ID", "Component Quantity", "Quantity Unit ID", "Mounting Place Related Machine Group ID", "Componen Setup"}; 

    public BomModel() { 
    } 

    public BomModel(List<JPartPosition> positionList){ 
     this.partPositionList = positionList; 

    } 

    @Override 
    public int getRowCount() { 
     return partPositionList.size(); 
    } 

    @Override 
    public int getColumnCount() { 
     return 12; 
    } 

    @Override 
    public Object getValueAt(int rowIndex, int columnIndex) { 

     Object value = "??"; 
     JPartPosition jpart = partPositionList.get(rowIndex); 
     switch (columnIndex) { 
      case 0: 
       value = jpart.getPartHeaderId(); 
       break; 
      case 1: 
       value = jpart.getMountingPlace(); 
       break; 
      case 2: 
       value = jpart.getPartNumber(); 
       break; 
      case 3: 
       value = jpart.getComponentType(); 
       break; 
      case 4: 
       value = jpart.getDescription(); 
       break; 
      case 5: 
       value = jpart.getPcbLayerId(); 
       break; 
      case 6: 
       value = jpart.getProcessingTypeId(); 
       break; 
      case 7: 
       value = jpart.getComponentQuantity(); 
       break; 
      case 8: 
       value = jpart.getQuantityUnitId(); 
       break; 
      case 9: 
       value = jpart.getMountingPlaceRelatedMachineGroupId(); 
       break; 
      case 10: 
       value = jpart.getComponentSetup(); 
       break; 
       //do i need the ID???//////////////// 
     } 

     return value; 
    } 

     public JPartPosition getMatAt(int row) { 
     return partPositionList.get(row); 
    } 

    @Override 
    public String getColumnName(int col) { 
     return columnNames[col]; 
    } 

} 

的代碼,我用它來分配表型號線正常工作,例如,如果它包含在一個JTable一個JFrame,但它不會在JDialog中工作。我需要這張表在JDialog中的原因是因爲我需要暫停主應用程序,同時用戶在JDialog中選擇一個值,然後在主應用程序中使用它。我發佈了另一個與此相關的問題,我之前試圖爲此使用JFrame,但這不是我需要的方式。我將離開鏈接以供參考。 Continue code execution after new JFrame is created and then closed

回答

0

看起來你有11個大小列名的數組,但你的getColumnCount方法返回12

+0

哇,我覺得如此愚蠢!哈哈哈哈,謝謝你有點陌生 –