Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do detect double-click on a JTable row?

Posted on 2000-04-04
3
Medium Priority
?
2,044 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 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

916 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