简体   繁体   English

在没有渲染器的JTable单元中设置JButton

[英]Setting a JButton in a JTable cell, without renderer

the problem i am facing is the following. 我面临的问题如下。 I am doing a little Java project and i need to display a JTable of Strings with the last column being a JButton. 我正在做一个小Java项目,我需要显示JTable of Strings,最后一列是JButton。 I read the existing solutions but none suit my needs. 我阅读了现有的解决方案,但没有一个适合我的需求。 The thing is that i already got my JButton with a preassigned controller and everything, so i don't want to add other classes or anything. 事实是,我已经拥有带有预分配控制器和所有内容的JButton,因此我不想添加其他类或任何东西。

What i want is my JButton, who is already correctly prepared, to be display in the JTable. 我想要的是我的JButton,它已经正确准备好了,可以显示在JTable中。 If that is not possible I would like to know if there is a way to display a JButton not in a JTable cell but next to the last cell of every row. 如果不可能,我想知道是否有一种方法可以显示JButton而不是在JTable单元格中,而是在每行的最后一个单元格旁边。 Thank you for your help. 谢谢您的帮助。

It's not really possible... It would require... I don't even know. 这是不可能的……这将需要……我什至不知道。 I don't think its possible 我认为这不可能

The problem is that Swing components (like JTable) don't actually contain other components. 问题在于,Swing组件(如JTable)实际上并不包含其他组件。 They use a Renderer to render the graphics of the table, but there's no plumbing for events like button clicks. 他们使用Renderer渲染表格的图形,但是没有诸如按钮单击之类的事件发生。

You'd be better off using a regular JPanel with a GridLayout or a GridBagLayout if you need this functionality 如果需要此功能,最好将常规JPanel与GridLayout或GridBagLayout一起使用

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

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