Solved

How do detect double-click on a JTable row?

Posted on 2000-04-04
3
1,950 Views
Last Modified: 2012-08-14
Hi,

I have a JTable which contains some rows of data, and is uneditable. When the user double-clicks or press Enter on a row, I would like to show him details of the data on that row.

My questions are:
1. How do I listen to a double-click mouse event on a row?
2. How do I listen to an Enter key event on a row?
3. When the Enter key is pressed on a row, how can I prevent the cell cursor from moving down to the next row. In other words, I want the row selection to be unaffected by the Enter key.
4. When the user presses the Tab key, I want the focus to shift to the next component (possibly a JButton), instead of just moving among the JTable cells.
0
Comment
Question by:yongsing
3 Comments
 
LVL 6

Accepted Solution

by:
expertmb earned 100 total points
ID: 2686785

>>1. How do I listen to a double-click mouse event on a row?
   table.addMouseListener(new java.awt.event.MouseAdapter() {

      public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                   //mycode
           }

      }
    })

mb...
0
 
LVL 9

Author Comment

by:yongsing
ID: 2705959
That works. How about keyboard events? I tried to add a key listener but it didn't work.
0
 

Expert Comment

by:Embt
ID: 3654597
to be more specific, here is the code for double-click on the right button:

//....

int m = event.getModifiers();

  if(event.getClickCount() > 1 && (m & InputEvent.BUTTON1_MASK) != 0 ) {
       //handling code..
}

have you got the problem solved? the above code only handled double-click on the whole table, how do you do to bring up the details on a specific row?

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Application launch issue with Apache Tomcat 5 21
allswap challenge 6 79
mockito example issue 8 62
MySqlDump not dumping triggers 1 17
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
The viewer will learn how to implement Singleton Design Pattern in Java.

911 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