简体   繁体   English

更新JTable单元格中的值

[英]Update values in a cell of a JTable

I want to put subject results in a Jtable. 我想将主题结果放在Jtable中。 I set DefaultTableModel to the table. 我将DefaultTableModel设置为表。 In my table I have three columns.Student ID,Marks and Grade.Student ID is auto generated in column one.then user should enter marks for for second column.Then I want to automatically put the necessary grading in 3rd column.I load the grading data from the database and find the correct grading for the marks.I try this with both MouseReleaseEvent and KeyReleaseEvent.But it wasn't successful.Can any one suggest me a better way.thank you. 在我的表格中,我有三列。学生ID,分数和成绩。学生ID在第一列中自动生成。然后用户应在第二列中输入标记。然后我要在第三列中自动添加必要的评分。从数据库中对数据进行分级并找到标记的正确分级。我同时使用MouseReleaseEvent和KeyReleaseEvent尝试了此尝试,但未成功,有人可以建议我一种更好的方法。谢谢。

You don't have to listen for the input events, because the table has cell editors already. 您不必监听输入事件,因为该表已经具有单元格编辑器。 So you should be capable of editing your table. 因此,您应该能够编辑表格。 The only thing you need to do is to listen for the tableChanged event and update the database there. 您唯一需要做的就是监听tableChanged事件并在那里更新数据库。

See: TableModelListener 请参阅: TableModelListener

In case I was confused by your thoughts about the events and you just want to basically set values of a cell programmatically, try this method: setValueAt(Object,int,int) 如果您对事件的想法感到困惑,而您只是想以编程方式基本上设置单元格的值,请尝试以下方法: setValueAt(Object,int,int)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM