1

インデックス[0][2]の合計値を計算したいのですが、前回値が0なのですが、計算結果「1/y」に置き換えて表示しており、合計値を計算すると合計した値が前回値になります「0」を含むもの、これが私のコード、

     //observation table
                                     //0             1        2    3      4      5     6                       
     titleColumn = new Object[]{"Time (Second)","Medicine", "1/y","x2", "X/Y", "Y^", "Error"};
                               //0   1    2   3   4   5   6
    allData = new Double[][]  {{1.0,1.02,0.0,0.0,0.0,0.0,0.0},
                               {2.0,0.667,0.0,0.0,0.0,0.0,0.0},
                               {3.0,0.367,0.0,0.0,0.0,0.0,0.0},
                               {4.0,0.278,0.0,0.0,0.0,0.0,0.0},
                               {5.0,0.237,0.0,0.0,0.0,0.0,0.0},
                               {6.0,0.187,0.0,0.0,0.0,0.0,0.0},
                               {7.0,0.155,0.0,0.0,0.0,0.0,0.0},
                               {8.0,0.156,0.0,0.0,0.0,0.0,0.0},
                               {9.0,0.142,0.0,0.0,0.0,0.0,0.0},
                               {10.0,0.111,0.0,0.0,0.0,0.0,0.0},
                               {11.0,0.12,0.0,0.0,0.0,0.0,0.0},
                               {12.0,0.097,0.0,0.0,0.0,0.0,0.0},
                               {13.0,0.099,0.0,0.0,0.0,0.0,0.0},
                               {14.0,0.089,0.0,0.0,0.0,0.0,0.0},
                               {15.0,0.079,0.0,0.0,0.0,0.0,0.0},
                               {0.0,0.0,0.0,0.0,0.0,0.0,0.0}};

    tableModelObservation = new DefaultTableModel(allData, titleColumn);
    tableObservation.setModel(tableModelObservation);
    int row,column,inputRow,inputColumn;

    //index [0][2] was replaced with calculation 1/y
    row = 0;
    column = 1;
    inputRow = 0;
    inputColumn = 2;
    double onePerY = 0;
    for(int a=0;a<allData.length;a++){
        onePerY = 1/allData[row][column];
        //is this the way to use getValueAt() and for indicating that the dependent cell has been change ?
        tableObservation.getModel().getValueAt(row, column);
        tableObservation.firePropertyChange("1/y", inputRow, inputColumn);
        tableObservation.getModel().setValueAt(onePerY, inputRow, inputColumn);  
        inputRow++;
        row++;
    }    

    //calculation total 1/y, summing is still using previous value "0"
    row = 0;
    column = 2;
    inputRow = 15;
    inputColumn = 2;
    double totalOnePerY = 0;
    for (int a=0;a<allData.length;a++){
        totalOnePerY += allData[row][column];
        row++;
    }
    //displaying result in row index[15] and column index[2] 
    tableObservation.getModel().setValueAt(totalOnePerY, inputRow, inputColumn);

計算処理後のこの列の値「1/y」 列 1/年

新しい値を使用して合計できるようにするにはどうすればよいですか? あなたがくれたすべての援助、私はそれを感謝します、ありがとう

4

2 に答える 2

5

に示すようにDependentColumn、の実装で派生値を計算できますgetValueAt()。値が依存する列が編集可能である場合は、依存セルが変更されたことを示すイベントを必ず発生させてください。

補遺:コードを getValueAt()に追加しましたが、結果は同じです。

推測しているsscceがありません:配列を作成および更新するために使用したallData、配列にアクセスしていることがわかります。演習の目的はわかりませんが、更新する前にアレイを更新する必要はないでしょう。内部で使用し、構築が完了した後は配列を無視します。DefaultTableModelDefaultTableModelVector

于 2013-01-18T07:00:04.460 に答える
2

EnvelopeTableMode元のモデルをラップし、グループ化機能 (SUM、COUNT、AVG...) を提供できる whichを使用してみることができます。

于 2013-01-18T07:13:36.867 に答える