关于这个问题我已查了好多资料了,但还是没有找到解决方法,
主要可能是由于JTable的开始编辑是由mouseclick来触发,所以可能键盘无法响应,
我想可能 的解决方法就是检测用户按下tab键后就模拟触发一次mouseclick事件,
看行不行了。

解决方案 »

  1.   

    我想可能 的解决方法就是检测用户按下tab键后就模拟触发一次mouseclick事件
    同意
      

  2.   

    to:skyyoung(路人甲) 
    你觉得触发mouseclick事件可行吗?
    怎么来触发呢,这可没有触发键方便哦!
      

  3.   

    触发mouseclick事件也许可以,但怎样定位位置?
    请继续讨论?
    老外可有讨论?
      

  4.   

    java.awt.RobotThis class is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed. Check the JDK document to find out how to do .Good luck!
      

  5.   

    import java.awt.*;
    import javax.swing.*;import javax.swing.event.*;
    import java.awt.event.*;
    import java.util.*;public class TableTest extends JFrame
    {
      JTable jTable1 = new JTable(3,4);  public TableTest()
      {
        try 
        {
          jbInit();
        }
        catch(Exception e)
        {
          e.printStackTrace();
        }
      }  public static void main(String[] args)
      {
        TableTest tableTest1 = new TableTest();
        tableTest1.show();
      }  protected void processWindowEvent(WindowEvent e){
        if(e.getID()==e.WINDOW_CLOSING){
         System.exit(0);
        }
        super.processWindowEvent(e);
      }
      private void jbInit() throws Exception
      {
        this.setSize(300,400);
        this.getContentPane().add(jTable1, BorderLayout.CENTER);
       
        ListSelectionListener listener =  new MySelectionListner();
        jTable1.getSelectionModel().addListSelectionListener(listener);
        jTable1.getColumnModel().getSelectionModel().addListSelectionListener(listener);
      }  class MySelectionListner implements ListSelectionListener{
        public void valueChanged(ListSelectionEvent e){
           if(e.getValueIsAdjusting())
            return ;
           if(e.getLastIndex()==e.getFirstIndex())
            return;
           int row = jTable1.getSelectedRow();
           int col = jTable1.getSelectedColumn();
           System.out.println("selected row is :"+row+" selected column " + col);
           if(row>=0&&col>=0)
            {
            jTable1.editCellAt(row,col);
            System.out.println("aaaaaa");
            }
        }
      } 
    }抱歉,来完了,给我分:)
      

  6.   

    兄弟先try一下,定会给分,
    请漂流兄先到下面的帖子随便回复一下,我好给分。
    谢谢!!!http://www.csdn.net/expert/topic/128/128006.shtm 
      

  7.   

    import java.awt.*;
    import javax.swing.*;import javax.swing.event.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.table.*;
    public class TableTest extends JFrame
    {
      JTable jTable1 = new JTable(3,4);  public TableTest()
      {
        try 
        {
          jbInit();
        }
        catch(Exception e)
        {
          e.printStackTrace();
        }
      }  public static void main(String[] args)
      {
        TableTest tableTest1 = new TableTest();
        tableTest1.show();
      }  protected void processWindowEvent(WindowEvent e){
        if(e.getID()==e.WINDOW_CLOSING){
         System.exit(0);
        }
        super.processWindowEvent(e);
      }
      private void jbInit() throws Exception
      {
        this.setSize(300,400);
        this.getContentPane().add(jTable1, BorderLayout.CENTER);
       
        ListSelectionListener listener =  new MySelectionListner();
        jTable1.getSelectionModel().addListSelectionListener(listener);
        jTable1.getColumnModel().getSelectionModel().addListSelectionListener(listener);
      }  class MySelectionListner implements ListSelectionListener{
        int lastRow,lastCol;
        public void valueChanged(ListSelectionEvent e){
         /*  if(e.getValueIsAdjusting())
           {
            System.out.println("value is adjusting!!");
            return ;
           } */
           int row = jTable1.getSelectedRow();
           int col = jTable1.getSelectedColumn();
           if(lastRow==row && lastCol==col)
           {
            System.out.println("The same Cell");
            return;
           }       jTable1.getCellEditor(lastRow,lastCol).cancelCellEditing();
           System.out.println("selected row is :"+row+" selected column " + col);
           if(row>=0&&col>=0)
            {
              jTable1.editCellAt(row,col);
              TableCellEditor cellEditor = jTable1.getCellEditor(row,col);
              Component component = cellEditor.getTableCellEditorComponent
                              (jTable1,jTable1.getValueAt(row,col),true,row,col);
              component.requestFocus();
            }
        }
      }
     
    }这样可以在同一列中获得光标,可是不能用键盘换到不同列,我现在没时间,下午再看看问题出在哪儿
      

  8.   

    如果你重载了editor,看一看你的getcellcomponent(),这一行,返回的是不是textedit,如果不是,这个方法有点问题.
    为了检查是不是没有单击就不出现textedit,clickCountToStart设为2,看看双击会不会出现这样的问题.
      

  9.   

    谢谢 javafounder(漂流) bootcool(bootcool) 及所有弟兄