Solved

How do detect double-click on a JTable row?

Posted on 2000-04-04
3
1,940 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.

757 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

20 Experts available now in Live!

Get 1:1 Help Now