2013-01-17 1 views
1

coloumn 제목의 이름이 "1/y"라는 인덱스 [0] [2]의 변수 배열의 값을 바꾸려고합니다. 이전 값은 내가 계산 결과 값으로 대체 할,하지만 난 그것을 표시 할 때, 그 값이 여전히 0.0,Java의 계산 결과 값으로 JTable 값 바꾸기

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); 
    }  

는 어떻게해야합니까, 대체 할 수이 내 코드, 0.0 그거야? 당신이 준 모든 원조, 고맙습니다.

+0

에서 봐, 당신은하는 TableModel를 사용해야합니다. DefaultTableModel는 사용 가능한 TableModel입니다. –

답변

2

TableModel 값이 아닌 배열 값을 업데이트합니다. jTable.getModel().setValueAt()을 사용하여 inputRow, inputColoumn 및 해당 값을 전달하십시오. 모델을 편집 할 수 있어야합니다. DefaultTableModel을 사용하면 기본적으로 수정할 수 있습니다.

+0

2 시간 후에, 나는 자바 프로그램을 마침내 시도했다. 내 프로그램을 마쳤다. StanislavL에게 감사한다. – irwansyahazniel

2

DefaultTableModel을 읽고이를 사용하여 테이블에 대한 데이터를 저장하십시오. 테이블 모델에서 업데이트해야하는 데이터가 변경 될 때가 있습니다. 당신이 JTable가에 반영하기 위해 데이터 모델의 변경을 원하는 경우

는 또한 How to Use Tables