简体   繁体   English

哪种编辑和删除行方法更适合JTable?

[英]Which editing and removing row method is better for JTable?

I wanna ask that which method to edit a JTable is better than the other? 我想问问哪种编辑JTable的方法比其他方法更好?

  1. use setValueAt() function. 使用setValueAt()函数。
  2. Make a new model of JTable and feed its object to JTable. 创建一个新的JTable模型,并将其对象提供给JTable。

And also, how to remove a Row from JTable without using method 2 described above? 而且,如何不使用上述方法2从JTable删除行?

You would use the setValueAt method when you're changing one value at a time. 一次更改一个值时,可以使用setValueAt方法。

You would make a new TableModel when you're changing 25% or more of the rows at one time. 一次更改25%或更多的行时,您将创建一个新的TableModel。

If you use a DefaultTableModel as your TableModel, you can use the addRow or setValueAt methods to add a row and change a row value. 如果将DefaultTableModel用作TableModel,则可以使用addRow或setValueAt方法添加行并更改行值。 You can use the removeRow method to remove a row. 您可以使用removeRow方法删除一行。

Since the TableModel is associated with the JTable, any changes to the TableModel are reflected in the JTable. 由于TableModel与JTable相关联,因此对TableModel的任何更改都将反映在JTable中。 Any changes to the JTable by the user are reflected in the TableModel. 用户对JTable所做的任何更改都将反映在TableModel中。

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

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