Java 获取jtable的单元格值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18268663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 23:53:52  来源:igfitidea点击:

Get cell values of jtable

javaswingjtabletablecelleditor

提问by user2436012

I have a jtable with column item,quantity,rate and amount.If i enter value in quantity and press tab key the total amount is getting calculated that is working fine.But i need the amount to be calculated on typing the quantity. I want it to be done on key pressed of numbers or on typing number.I have used default jtable using netbeans

我有一个带有列项目、数量、费率和金额的 jtable。如果我输入数量值并按 Tab 键,则计算出的总量工作正常。但我需要在键入数量时计算数量。我希望它在按下数字键或输入数字时完成。我使用 netbeans 使用了默认的 jtable

回答by Sergii Zagriichuk

to get cell value you can to do something like that

要获得单元格值,您可以执行类似的操作

table.getModel().getValueAt(rowIndex, columnIndex)

回答by trashgod

In response to an answer suggesting getValueAt(), you say, "I used the above code but it prints as null." As discussed here, the value is not available in the model until the editor concludes. You'll need a custom TableCellEditorthat uses a DocumentListenerto update your total.

在回应建议 的答案时getValueAt(),您说:“我使用了上面的代码,但它打印为null。” 正如此处所讨论的,在编辑器结束之前,该值在模型中不可用。您将需要一个TableCellEditor使用 aDocumentListener来更新您的总数的自定义。