Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do detect double-click on a JTable row?

Posted on 2000-04-04
3
Medium Priority
?
2,021 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Accepted Solution

by:
expertmb earned 300 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

722 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