Mouse double click event in JTable

Posted on 2004-11-11
Last Modified: 2012-06-27
Hi, this is quite difficult to explain!
  I have a JTable.  When the user double clicks a row it opens the file represented by that row:

public void mousePressed(MouseEvent e)
    // if a double click then update the collection view
    if (e.getClickCount() == 2)
      Point origin = e.getPoint();
      int row = table.rowAtPoint(origin);
      if (row != -1)
        /** openFile( row ); */

So this file is opened in the work-area "panel" (dockable frame) below the table -> the last thing done is to activate (give focus to) this new file.
But then the focus jumps back to the tables frame - where the mouse-event occurred.
I can see how there is logic to this alright, but there is an anomoly which might help in providing a solution here:

if the cell that was double clicked IS editable, then the focus remains with the opened document*, if it IS NOT editable then focus jumps back to the table!

* NB! the focus stays with the opened document but in the table it looks like cell editing was cancelled or something (the specific cell has an edit box around it, but the cursor is not blinking because focus isnt even on that panel!)

Any ideas !?i?!
Question by:cathalmchale
    LVL 92

    Expert Comment

    Try queueing the request for focus using EventQueue.invokeLater().

    Author Comment

    OK - ill try.  how?? !!
    LVL 92

    Accepted Solution

    EventQueue.invokeLater(new Runnable()
       public void run()
          // add your code here

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
    Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now