- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想计算索引[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”
我应该怎么做才能使用新值对其求和?您给予的所有帮助,我将不胜感激,谢谢
最佳答案
如图DependentColumn
,您可以在 getValueAt()
的实现中计算派生值。如果值所依赖的列是可编辑的,请务必触发一个事件,指示相关单元格已更改。
附录:我用 getValueAt()
添加了我的代码,但结果是一样的。
缺少您的 sscce我猜:我看到您访问 allData
数组之后您使用它来构建和更新 DefaultTableModel
。我不确定练习的目标,但您可能不想在这样做之前更新数组。 DefaultTableModel
在内部使用 Vector
,构造完成后它会忽略数组。
关于java - 使用新值计算 JTable 列中的总值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14393809/
创建我用下面的代码制作了分布图: from numpy import * import numpy as np import matplotlib.pyplot as plt sigma = 4.1
我想我已经尝试了这方面的所有方法,但我无法弄清楚这一点。我只是想在用户增加数量时更新表中每一行的总价。到目前为止我已经尝试过 HTML 中的数学:data-bind="text: parseFloat
我的数据库中有一个表,如下所示: id | date | amount ======================== 1 | 2015-01-26 | 1000 2 | 2015-
我有一个条形图,总值通常重叠在上面,如下所示。我尝试减少图形的面积、宽度和高度,这个问题得到解决,但对于其他一些值再次出现,是否有任何永久的解决方案来避免重叠? 请查找下面的代码 $('#' + d
我一直在四处寻找,似乎找不到这个问题的答案,希望得到任何帮助。 简而言之,我有两个表:付款表和成员(member)表。 我已执行以下操作来查找成员(member) ID 与付款 ID 列中的 ID 匹
我是一名优秀的程序员,十分优秀!