禁用 JTable 上的用户输入

发布于 2024-09-07 15:13:47 字数 122 浏览 2 评论 0原文

有没有办法在创建 JTable 之后禁用对其进行编辑。 因为我的 JTable 是使用 GUI 工具自动创建的,所以我无法编辑创建 JTable 的源代码。

干杯

Is there a way to disable editing a JTable after creating it.
Because my JTable is created automaticly using GUI Tools and I cannot edit the source code where it creates the JTable.

Cheers

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

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

发布评论

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

评论(2

怀念你的温柔 2024-09-14 15:13:47

是的,但它在您的 TableModel 中。有一个名为 isCellEditable 如果你无法操作你的模型,可以尝试这样的事情:

jtableObject.setModel(jtableObject().getModel(){
   isCellEditable(int rowIndex, int columnIndex) {
       return false;
   }
});

你的对象必须被创建!这是一个有点令人困惑的代码。您正在创建一个匿名类。

请记住,当您谈论“编辑”时,您实际编辑的是存储在该表中的数据。数据在 TableModel 中表示。

Yes, but it's in your TableModel. There's a method called isCellEditable If you can't manipulate your model, can try something like this:

jtableObject.setModel(jtableObject().getModel(){
   isCellEditable(int rowIndex, int columnIndex) {
       return false;
   }
});

Your object must be created! It's a little confusing code. There you're creating an anonymous class.

Remember, when you talk about "editing", what you're actually editing, is the data stored in that table. The data is represented in the TableModel.

烟─花易冷 2024-09-14 15:13:47

如果您可以访问源代码,并且有对框架的引用,您仍然可以以编程方式遍历容器树,直到到达表,然后调用您需要的任何内容。

If you have access to the source code, and have a reference to the frame, you could still programatically traverse the container tree until you get to the table, then call whatever you need on it.

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