Java Swing:如何将 JLabel 的文本绑定到 JTable 的选定行中的列?
我正在使用 Netbeans,并试图找到一种让 IDE 为我自动生成代码的方法。我记得之前将 JLabel 的文本绑定到 JTable 的选定行中的列,但在这种情况下,JTable 的值来自实体管理器,而且非常简单。我想知道即使 JTable 没有绑定到数据库是否有办法做到这一点。
另外,还有什么办法可以做到这一点呢?我正在考虑实现一个 ListSelectionListener,每当生成事件时,只需更新标签的文本即可。
I am using Netbeans and am trying to find a way for the IDE to auto-generate the code for me. I remember binding a JLabel's text to a column in the selected row of the JTable before, but in that case, the JTable's values were from an entity manager, and it was very easy. I was wondering if there is a way to do it even if the JTable is not tied to a database.
Also, how else could one do it? I was thinking of implementing a ListSelectionListener, and whenever an event got generated, just update the text of the label.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的第二个解决方案是最好的方法,像这样:
然后
像这样。可能是一个更通用的解决方案,但这应该可行。
I think your second solution is best way to do it, something like this:
and then
Something like this. Probably a more generic solution, but this should work.