【问题标题】:Detect click on JTable: sometimes not recognized检测点击 JTable:有时无法识别
【发布时间】:2012-08-01 07:00:29
【问题描述】:

我有这段代码来检测对 JTable 的点击

table.addMouseListener(new java.awt.event.MouseAdapter()
{
    @Override
    public void mouseClicked(java.awt.event.MouseEvent e)
    {

        int row= table.rowAtPoint(e.getPoint());
        int col= table.columnAtPoint(e.getPoint());
        System.out.println(table.getSelectedRow());

        if (e.getClickCount() == 2)
        {

            System.out.println ("Doppio Click");

        }

    }

});

此代码工作得很好,问题是如果我单击一行并且在鼠标按钮向上之前将鼠标向上移动,则未检测到单击,但在我的 JTable 中选择了该行。谁能知道如何解决这个问题?谢谢!

【问题讨论】:

  • 使用 mouseDown 存储行/列(我个人将它放在点对象中,因为它更容易检测空值,但这只是我)然后在释放或单击方法中执行

标签: java swing jtable mouseevent mouseclick-event


【解决方案1】:

改用MouseListener.mouseReleasedMouseListener.mousePressed 事件(以这种方式检测双击比较麻烦,但可以做到)。

【讨论】:

  • 是的,这就是解决方案。在你回答之前我已经试过了,效果很好。问题在于现在双击!
猜你喜欢
  • 2021-09-06
  • 1970-01-01
  • 2018-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-09
  • 1970-01-01
相关资源
最近更新 更多