Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JTable鼠标侦听器工作不正常_Java_Swing_Concurrency_Jtable_Mouselistener - Fatal编程技术网

Java JTable鼠标侦听器工作不正常

Java JTable鼠标侦听器工作不正常,java,swing,concurrency,jtable,mouselistener,Java,Swing,Concurrency,Jtable,Mouselistener,我的JTable(jtblLot)鼠标单击事件有时不会触发。主要依靠频繁的点击 下面是鼠标单击事件的代码 private void jtblLot_MouseClicked(java.awt.event.MouseEvent evt) { int row = jtblLot.rowAtPoint(evt.getPoint()), currId = 0; int col = 3; lotId = jtblLot.getValueAt(row, col).

我的JTable(jtblLot)鼠标单击事件有时不会触发。主要依靠频繁的点击

下面是鼠标单击事件的代码

 private void jtblLot_MouseClicked(java.awt.event.MouseEvent evt) {       

    int row = jtblLot.rowAtPoint(evt.getPoint()), currId = 0;
    int col = 3;

    lotId = jtblLot.getValueAt(row, col).toString();
    if (jtblLot.getValueAt(row, 1) != null) {
    sizeGrp_up = jtblLot.getValueAt(row, 1).toString();
    } else {
    sizeGrp_up = "0";
    }

    if (jtblLot.getValueAt(row, 4) != null) {
    if (jtblLot.getValueAt(row, 4).toString().compareTo("") !=0)
    {
    currId = Integer.parseInt(jtblLot.getValueAt(row, 4).toString()) - 1;
    }
    } else {
    sizeGrp_up = "0";
    }

    cmbCurrency.setSelectedIndex(currId);
    jlblLotId.setText(lotId);

    // Sets Model For Another JTable(jtblLGP) In My Form Get Data From DB
    getLotGradePriceData();

    //On Click I get The Focus To The Clicked Cell
    int col_ = jtblLot.columnAtPoint(evt.getPoint());
    jtblLot.setCellSelectionEnabled(true);
    jtblLot.changeSelection(row, col_, false, false);
    jtblLot.scrollRectToVisible(new Rectangle(jtblLot.getCellRect(row, col_, true)));

} 

如果您需要处理每次单击,我建议您处理
mouseerelease
,而不是
mouseClicked

// Sets Model For Another JTable(jtblLGP) In My Form Get Data From DB
getLotGradePriceData();
  • ,您将阻止EDT,直到JDBC事件结束

  • 使用
    Runnable#Thread
    (所有到Swing GUI的输出,其XXX模型必须包装到
    invokeLater
    )或
    SwingWorker
    作为此作业的工作线程

  • 尽可能使用最简单的方法

  • 也许还有一些其他问题,为了更好地帮助您更快地发布一个简短的、可运行的、可编译的、使用局部变量而不是JDBC事件


当在同一点接收到mousePressed和MouseRelease事件时,将生成mmouse clicked事件。所以,如果鼠标在这两个事件之间移动一个像素,你就不会被鼠标点击。这就是你偶尔会遇到问题的原因。