简体   繁体   English

JTable 如何在行之间添加一行

[英]JTable How to add a row between rows

I've been looking for this quite a long time before and I can't find any question about this nor topic, I am assuming it might be impossible to do, though it seems odd as the feature would be useful.我一直在寻找这个很久以前,我找不到关于这个或主题的任何问题,我假设这可能是不可能的,尽管它看起来很奇怪,因为该功能很有用。

I would like in the situation when I have let's say 3 rows, to add another one not at the end, but after row number 1. Is that possible in any way?我想在我有 3 行的情况下,不是在最后添加另一行,而是在第 1 行之后添加。这有可能吗?

Please do not mention row arranging based on some id, as that is the last thing I would do in my situation.请不要提及基于某些 id 的行排列,因为这是我在我的情况下会做的最后一件事。

Use a DefaultTableModel <- see docs more contructors使用DefaultTableModel <- 请参阅文档更多构造函数

DefaultTableModel model = new DefualtTableModel(String colNames, int rows);
JTable table = new JTable(model);

Then you can use one of the following methods然后您可以使用以下方法之一

Or或者


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

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