someJTable.addMouseListener(new MouseAdapter() {
  public void mouseClicked(MouseEvent e) {
    if (e.getClickCount() == 2) {
      //do something
    }
  }});

解决方案 »

  1.   

    如果这样做的话,全部的cell都会响应这个事件,有没有办法只让某几个cell,或者说某一列cell响应?另外怎么响应mouseenter事件?
      

  2.   

    (COPY)
    You will have to subclass JTable and override the following three methods - 
    public Component prepareEditor(TableCellEditor editor,int row, int column)
    Prepares the editor by querying the data model for the value and selection state of the cell at row, column. 
    public void editingCanceled(ChangeEvent e)
    Invoked when editing is canceled. The editor object is discarded and the cell is rendered once again. 
    public void editingStopped(ChangeEvent e)
    Invoked when editing is finished. The changes are saved and the editor is discarded. 
    In the prepareCellEditor first call the super.prepareCellEditor(...). On the returned component add the FocusListener. Now whenever the editor component gets focus the focusGained(..) of the focus listener will be called. Ditto for focus loss. In the editingCancelled(..) and editingStopped(...) remove the FocusListener. 
      

  3.   

    关于表格事件主要有以下几种:
    TableModelEvent :当单元值变化,表格变化,单元更新时使用.
    TableColumnModelEvent:列变化时.
    ListSelectionEvent :行选取时变化.
    ChangeEvent :编辑被停止/取消.JTable class 不提供任何添加监听器的方法.
    监听器需直接添加到一个表格的三种模型或一个单元编辑器上.这是我抄的一个程序,希望对你有帮助.import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.awt.event.*;public class Test extends JFrame {
    JTable table = new JTable(10,10); public Test() {
    Container contentPane = getContentPane(); contentPane.add(new JScrollPane(table),
    BorderLayout.CENTER); table.getModel().addTableModelListener(
    new TableModelListener() {
    public void tableChanged(TableModelEvent e) {
    int firstRow = e.getFirstRow(),
    column = e.getColumn(); String properties = " source=" + e.getSource() +  
                 " firstRow= " + 
    (firstRow == TableModelEvent.HEADER_ROW ?
    "HEADER_ROW" : 
    Integer.toString(firstRow)) +             " lastRow= " + e.getLastRow() +              " column= " + 
      (firstRow == TableModelEvent.ALL_COLUMNS ?
    "ALL_COLUMNS" : 
    Integer.toString(column)); String typeString = new String();
    int type = e.getType(); switch(type) {
    case TableModelEvent.DELETE:
     typeString = "DELETE"; break;
    case TableModelEvent.INSERT:
     typeString = "INSERT"; break;
    case TableModelEvent.UPDATE:
     typeString = "UPDATE"; break;
    }
    properties += " type=" + typeString;    JOptionPane.showMessageDialog(Test.this, 
      e.getClass().getName() + 
    "[" + properties + "]");
    }
    });
    }
    public static void main(String args[]) {
    new Test().show();

    }
    }
      

  4.   

    当鼠标进入一个jtable的某一个cell中,更改cursor,并且让这个cell可以响应鼠标的单击事件
    简单做法:JTable 中加入鼠标时件监听器,鼠标移动时看看是否在某个cell上
      

  5.   

    //这是我想的办法,可是只能得到某个cell在表中的位置,当然也可使其响应其它事件.
    //但是一次只能选取一个cell而不能是几个不在同一行或列的值.
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.awt.event.*;public class Test extends JFrame {
    JTable table = new JTable(10,10); public Test() {
    Container contentPane = getContentPane();
        contentPane.add(new JScrollPane(table),BorderLayout.CENTER);
          table.addMouseListener(new MouseAdapter() { 
                public void mouseClicked(MouseEvent e) { 
                 int i = table.rowAtPoint(e.getPoint()); 
                 int j = table.columnAtPoint(e.getPoint());
                 System.out.println("<"+i+","+j+">");
               } 
         }); 
     }

     public static void main(String args[]) {
     Test test = new Test();
     test.addWindowListener(new WindowAdapter() { 
            public void windowClosing(WindowEvent e) { 
               System.exit(0); 
             } 
         }); 
        test.pack(); 
        test.setVisible(true);
     }
    }你也可以去:http://www.codeguru.com/java/articles/663.shtml看看.
    那有对你的问题的完整解答.有一个自写的table类.我想是符合你的需要的.