本文介绍了Java中的侦听器顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了自己的表格单元格编辑器,扩展了 AbstractCellEditor 并实现了 TableCellEditor ItemListener ,以及 MouseListener 。有没有办法在 itemStateChanged 方法之前先执行 mouseClicked 方法?我正在尝试执行以下操作:

I wrote my own table cell editor that extends an AbstractCellEditor and implements a TableCellEditor, an ItemListener, and a MouseListener. Is there a way I can have the mouseClicked method be executed first before the itemStateChanged method? I'm trying to do the following:

private int rowClicked;
private JTable table;

public void itemStateChanged(ItemEvent e) {
  if (rowClicked == 5) {
    // Do something to row 5.
  }
}

public void mouseClicked(MouseEvent e) {
  Point p = e.getPoint();
  rowClicked = table.rowAtPoint(p);
}


推荐答案

这是一篇很好的文章解释没有听众通知顺序:

Here is a nice article explaining the absence of listener notification order in swing:Swing in a better world

这篇关于Java中的侦听器顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 12:03