简体   繁体   English

双击JTable

[英]Double click JTable

The cells in my JTable become editable only on the second click. 我的JTable中的单元格仅在第二次单击时才可编辑。 When I debugged I noticed that on the second click the mouse released event is not fired. 调试时,我注意到第二次单击时未触发鼠标释放事件。 I saw a lot of answers for this problem with create a setSingleClick(1)... but it doesn't to work. 通过创建setSingleClick(1),我看到了很多针对此问题的答案,但是它不起作用。 I think that if i can get that second mouseReleased event to get fire i might be able to make it work. 我认为,如果我可以使第二个mouseReleased事件发生火灾,我也许可以使其工作。 Does anybody has any sugestions? 有人有任何建议吗?

table.addMouseListener(new TableMouseListener()) ;
class TableMouseListener extends MouseAdapter{
        public void mousePressed(MouseEvent e) {
         System.out.println("mousePressed");
        }
        public void mouseClicked(MouseEvent e) {
            System.out.println("mouseClicked"); 
        }
       public void mouseReleased(MouseEvent e) {
          System.out.println("mouseReleased");
       }
}

Try something like this: 尝试这样的事情:

container_table.addMouseListener(new MouseAdapter() {

        public void mouseClicked (MouseEvent me) {
            if (me.getClickCount() == 2) {
                //Double clicked
            }
        }
    });

This way, you know that the 'container_table' has been clicked twice, and then you can get the selected row, and make things with it. 这样,您知道已经两次单击了“ container_table”,然后可以获取所选的行并进行处理。

Hope it helps. 希望能帮助到你。

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

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