2012-08-14 77 views
2

我幾乎沒有困惑。我正在嘗試更新JTable,但更新不會出現。這是我現在的代碼:更新JTable

private void addTable(){ 

     table = new JTable();// the table for 'Benchmark' tab 
     table.setShowVerticalLines(false); 
     table.setBorder(null); 

     data = new Object[][] { 
       {"Key", ""},//result[0] 
       {"Precision", ""},//result[2]+" %" 
       {"Cipher", ""},//result[4] 
       {"Language", ""}, 
       {"Performance", ""},//result[3] 
     }; 


     String [] header = new String[] {"Subject of Interest", "Output"}; 
     model = new DefaultTableModel(data, header);   

     table.setModel(model); 


     table.getColumnModel().getColumn(0).setPreferredWidth(136); 
     table.getColumnModel().getColumn(1).setPreferredWidth(550); 
     GroupLayout gl_panelBenchmark = new GroupLayout(panelBenchmark); 
     gl_panelBenchmark.setHorizontalGroup(
       gl_panelBenchmark.createParallelGroup(Alignment.TRAILING) 
       .addComponent(textInfoCrypto, GroupLayout.DEFAULT_SIZE, 759, Short.MAX_VALUE) 
       .addGroup(gl_panelBenchmark.createSequentialGroup() 
         .addGap(10) 
         .addComponent(textPane, GroupLayout.DEFAULT_SIZE, 739, Short.MAX_VALUE) 
         .addGap(10)) 
         .addGroup(Alignment.LEADING, gl_panelBenchmark.createSequentialGroup() 
           .addContainerGap() 
           .addComponent(table, GroupLayout.DEFAULT_SIZE, 739, Short.MAX_VALUE) 
           .addContainerGap()) 
       ); 
     gl_panelBenchmark.setVerticalGroup(
       gl_panelBenchmark.createParallelGroup(Alignment.LEADING) 
       .addGroup(gl_panelBenchmark.createSequentialGroup() 
         .addContainerGap() 
         .addComponent(textInfoCrypto) 
         .addPreferredGap(ComponentPlacement.UNRELATED) 
         .addComponent(textPane, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE) 
         .addPreferredGap(ComponentPlacement.UNRELATED) 
         .addComponent(table, GroupLayout.PREFERRED_SIZE, 79, Short.MAX_VALUE) 
         .addContainerGap()) 
       ); 
     panelBenchmark.setLayout(gl_panelBenchmark); 

    } 

這就是我在這個階段嘗試更新單行的方法。下面的代碼是從另外的方法調用:

data[0][0]= result[0]; 
model.fireTableCellUpdated(0, 0); 

在這個階段,我只能看到有行名稱的表框,但沒有數據。請幫忙嗎?

回答

2
  1. 所有fireXxxXxx事件DefaultTableModel正確實施及

  2. 的JTable在這個距離,並根據DefaultTableModel有不更新modelToView的或ViewToModel,有任何問題沒有限制,

  3. 必須編輯你的探索與SSCCE

  4. 之前

    閱讀JTable tutorial

  5. 尤其JTable and TableModel

+0

我喜歡讀它,說實話,但是這是非常緊迫的。我沒有時間從頭開始學習我遇到的所有問題。 – uml 2012-08-14 12:41:11