Netbeans 中的 JTable 右键单击弹出菜单
我想在 NetBeans IDE 中向 JTable 添加右键单击弹出菜单(似乎是一个简单的任务...哈哈)
将其部分工作,
- 我通过向表单添加弹出菜单
- 将菜单项添加到弹出菜单
- 转到 JTable
- 单击绑定 的属性选项卡
- 将 ComponentPopupMenu 值设置为我的 popupmenu
但这仅部分有效。 现在,当我右键单击表时,会弹出菜单,但 JTable 中选定的行不会更改。因此,当调用 menuitem 的 actionPerformed 时,我不知道单击了 JTable 中的哪一行。
我怎样才能得到这个?或者有没有更简单的方法在 netbeans 中做到这一点?
我知道还有其他方法可以做到这一点(在代码中),但我更喜欢使用 netbeans GUI 构建器。
以前有人这样做过吗?
感谢您的帮助!
I want to add a right click popupmenu to a JTable in NetBeans IDE (seems like a simple task... lol)
I got it to partly work by
- adding a popupmenu to the form
- adding menuitems to the popupmenu
- go to properites of JTable
- click binding tab
- set ComponentPopupMenu value to my popupmenu
But this only partly works.
Now I when I right click on the Table the menu pops up, but the selected row in the JTable does not change. So in when the menuitem's actionPerformed is called I have no idea what row in the JTable was clicked on.
How can I get this? or is there an easier way to do this in netbeans?
I know there are others ways of doing this (in code), but I would prefer to use netbeans GUI builder.
Has anyone ever done this before?
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么要依赖 IDE 来生成代码?当您转移到不同的 IDE 并且您必须学习如何为该 IDE 执行此操作时会发生什么?了解如何编写自己的代码,那么 IDE 就不再重要了:
Why do you rely on an IDE to generate code for you? What happens when you move to a different IDE and you have to learn how to do it for that ide? Learn how to write your own code then the IDE doesn't matter:
希望我能为 Netbeans 回答这个问题...我希望这可以帮助有人
jPopupMenu 例如,
将 ComponentPopupMenu 值设置为我调用的 jPopupMenu
下一步,
在属性中选择 Events 并转到 mouseReleased 将其设置为您的 jTableDataOrSomething (或右键单击表,Events > Mouse > mouseReleased )
Netbeans 创建一个空函数并设置以下代码
create对每个菜单项执行的 menuitem 操作
然后你可以在其中使用:
这需要多行选择并考虑排序/过滤。
完成该函数
使用Enjoy
Hopefully I can answer it for Netbeans... and I hope this helps someone
jPopupMenu for example
set ComponentPopupMenu value to my called jPopupMenu
Next steps,
while in properties select Events and goto mouseReleased set it to your jTableDataOrSomething (or right click on table, Events > Mouse > mouseReleased)
Netbeans creates an empty function and set the following code
create the menuitem action performed for EACH menu item
Then in there you can use:
This takes multirow selection and considers sorting/filtering.
Finish the function with
Enjoy