Netbeans中的JTable右键单击弹出菜单

编程入门 行业动态 更新时间:2024-10-27 16:31:06
本文介绍了Netbeans中的JTable右键单击弹出菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在NetBeans IDE中向JTable添加一个右键单击popupmenu(好像一个简单的任务……大声笑)

I want to add a right click popupmenu to a JTable in NetBeans IDE (seems like a simple task... lol)

我想让它部分起作用

  • 在表单中添加弹出菜单
  • 将菜单项添加到弹出菜单
  • 转到JTable的属性
  • 单击绑定选项卡
  • 将ComponentPopupMenu值设置为我的弹出菜单
  • 但这仅部分起作用. 现在,当我右键单击Table时,会弹出菜单,但是JTable中的选定行不会更改.因此,在调用menuitem的actionPerformed时,我不知道单击了JTable中的哪一行.

    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.

    我怎么能得到这个?还是在netbeans中有更简单的方法来做到这一点?

    How can I get this? or is there an easier way to do this in netbeans?

    我知道还有其他方法(在代码中),但是我更喜欢使用netbeans GUI构建器.

    I know there are others ways of doing this (in code), but I would prefer to use netbeans GUI builder.

    以前有人做过吗?

    感谢您的帮助!

    推荐答案

    为什么要依靠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:

    table.addMouseListener( new MouseAdapter() { public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { JTable source = (JTable)e.getSource(); int row = source.rowAtPoint( e.getPoint() ); int column = source.columnAtPoint( e.getPoint() ); if (! source.isRowSelected(row)) source.changeSelection(row, column, false, false); popup.show(e.getComponent(), e.getX(), e.getY()); } } });

    更多推荐

    Netbeans中的JTable右键单击弹出菜单

    本文发布于:2023-08-06 05:15:19,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1310282.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:右键   弹出   单击   菜单   Netbeans

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!