是否可以在JTable中包含JButton? [英] Is it possible to include JButton in a JTable?

查看:118
本文介绍了是否可以在JTable中包含JButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个存储数据库查询结果的JTable,到目前为止一直很好。我想要的是每个表中的最后一列有一个可点击的JButton,它将打开该行中表示的对象的编辑屏幕,这意味着该按钮需要知道表中第一列的详细信息拥有行(数据库中的ID)。

I have a JTable that stores the results of a database query, so far so good. What I want is for the last column in each table to have a clickible JButton that will open the edit screen for the object represented in that row, and that means the button will need to know the details of the first column in the table from its own row (the ID from the database).

有什么建议吗?我已经尝试过添加JButton,但是当我尝试运行它时它们变成了Text。

Any advice? I already tried just adding JButtons but they turned into Text when I tried to run it.

推荐答案

与上面的教程相反,有一种方法可以做到这一点,而无需复杂的定位数学,自定义鼠标监听器和自定义表模型。相反,它可以使用一个简单的自定义类,遵循此处描述的模式:

Contrary to the tutorial above, there is a way to do this without a complicated positioning math, custom mouse listeners, and custom table models. Instead, it can be done with a single simple custom class following the pattern described here:

http://web.archive .org / web / 20100623105810 / http://ivolo.mit.edu/post/A-Simple-Pattern-for-Embedding-Components-into-a-Swing-JTable.aspx

这篇关于是否可以在JTable中包含JButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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