1

列タイトルの名前が「1/y」であるインデックス[0][2]の変数配列の値を置き換えたい。以前の値は 0.0 です。計算結果の値に置き換えたいのですが、表示しようとすると、その値はまだ 0.0 です。これは私のコードです

titleColoumn = 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},
                                    {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}};

    tableObservation = new DefaultTableModel(allData, titleColoumn);
    table.setModel(tableObservation);

    int row,coloumn;
    //calculation 1/y
    row = 0;
    coloumn = 1;
    int inputRow = 0;
    int inputColoumn = 2;
    double onePerY;
    for(int a=0;a<allData.length;a++){
        onePerY = 1/allData[row][coloumn];
        //replace value
        allData [inputRow][inputColoumn] = onePerY;
        inputRow++;
        row++;
        System.out.println(onePerY);
    }    

交換するにはどうすればいいですか?あなたがくれたすべての援助、私はそれを感謝します、ありがとう

4

2 に答える 2

2

値ではなく配列値を更新しTableModelます。jTable.getModel().setValueAt()inputRow、inputColoumn、およびそれらに適切な値を渡すことを使用します。モデルは編集可能でなければなりません。使用する場合DefaultTableModel、デフォルトで編集可能です。

于 2013-01-17T16:59:21.363 に答える
2

DefaultTableModelについて読み、それを使用してテーブルのデータを保存します。データに変更があるたびに、テーブル モデルを更新する必要があります。

テーブルの使い方も参照してください。

于 2013-01-17T17:12:23.143 に答える