我无法在我的 java 项目中检测到点击次数 = 2(双击)

I can't detect click count = 2 (double click) in my java project

我正在尝试监听 jtable 上的双击,但鼠标监听器只接收到点击次数 = 1。

JTable replacedAssets = new JTable(...);
replacedAssets.addMouseListener ( new MouseAdapter ( ) {
        @Override
        public void mouseClicked ( MouseEvent e ) {
            super.mouseClicked ( e );
            if ( e.getClickCount () == 2 ) {
                rowIndex = replacedAssets.getSelectedRow ();
                columnIndex = replacedAssets.getSelectedColumn ();
                if ( rowIndex == 0 && ( columnIndex == 1 || columnIndex == 2 ) ) {
                    initial = replacedAssets.getValueAt ( rowIndex , columnIndex );
                    JOptionPane.showMessageDialog ( parent , "Editing this Field may cause error in the data causing problems." , "Error Edit Not Permitted For This Field" , JOptionPane.ERROR_MESSAGE );
                }
            }
        }
    } );

这是我的鼠标监听器代码 请帮忙。 PS: JLabel 正常工作

mousePressed 替换 mouseClicked 对我有用。我相信这是因为 mouseClickmousePressedmouseReleased 的组合。即使鼠标在两个事件之间移动一个像素,也不会生成事件。

replacedAssets.addMouseListener (new MouseAdapter(){
            @Override
            public void mousePressed(MouseEvent mouseEvent) {
                super.mousePressed(mouseEvent);
                JTable table = (JTable) mouseEvent.getSource();
                if (mouseEvent.getClickCount() == 2 ) {
                    System.out.println("Double click detected");
                }
           }
   });