JTable如何在行之间添加行 [英] JTable How to add a row between rows

查看:103
本文介绍了JTable如何在行之间添加行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前一直在寻找这个问题,我找不到任何关于这个或主题的问题,我假设它可能是不可能做到的,虽然这看起来很奇怪,因为这个功能很有用。 / p>

我想在这种情况下,我说3行,添加另一个不在最后,但在第1行之后。这有可能吗?



请不要提及基于某些ID的行安排,因为这是我在我的情况下要做的最后一件事。

解决方案

使用 DefaultTableModel < - 查看docs more contructors

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

然后您可以使用以下方法之一











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?

Please do not mention row arranging based on some id, as that is the last thing I would do in my situation.

解决方案

Use a DefaultTableModel <- see docs more contructors

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

Then you can use one of the following methods

Or


这篇关于JTable如何在行之间添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆