如何更改 JTable 单元格中的数据?

发布于 2024-07-09 13:46:06 字数 165 浏览 4 评论 0原文

我可以在 JTable 构造函数中设置数据,然后用户可以在程序手动运行时(从键盘输入)更改此数据。

但是如果我想更改某些列中的数据,应该使用什么方法呢? 要更改列标题,我使用 TableColumn 方法 setHeaderValue。 我应该使用什么来设置 JTable 单元格中的值?

I can set data in JTable constructor, and then user can change this data when program is running manually(typing from keyboard).

But what method should I use in case I want to change data in some column? To change column header I use TableColumn method setHeaderValue. What should I use to set value in JTable cell?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔少女心 2024-07-16 13:46:06

如果您想允许用户编辑数据,那么您需要在您希望人们编辑的单元格上设置 TableCellEditor。 您可能还想开始使用 TableModel,而不是对 JTable 本身中的数据进行硬编码。

请参阅 http://java.sun.com/docs/books /tutorial/uiswing/components/table.html

If you want to allow users to edit the data, then you need to set a TableCellEditor on the cells that you want people to edit. You probably also want to start using a TableModel instead of hard coding the data in the JTable itself.

See http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

两个我 2024-07-16 13:46:06

创建 JTable 时,您首先需要指定特定列的值是可编辑的。 显然,您还可以提供基于行的编辑功能。 但所有这些内容都应该在创建表本身时定义。 如果您需要任何帮助,请回复。

While creating the JTable you first need to specify that the values of particular column are editable. You can obviously also provide the row basis edit functionality. but all these things you should define while ccreating the table itself. Please reply if you need any help on this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文