Solved

How do detect double-click on a JTable row?

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
more than one jdk and one jre 1 50
java jdbc batch example 8 41
jboss wildfly 10.1 10 230
Why doesn't this text field show up on my Applet frame? 2 19
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

860 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