Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JTable, how to get mouse click event here?

Posted on 2007-03-19
5
Medium Priority
?
5,705 Views
Last Modified: 2012-05-05
Hello experts,

I am writing Swing application using JTable.. exactly what I am doing is based on TableDemo.java that exists in http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

But then I modified the code inside TableModel.java by taking out the inner class of TableModel.java into a separate class, i called it MyTableModel.java.

So the result is MyTableModel.java & TableModel.java. MyTableModel.java will accept an array list as data source. And after I have MyTableModel.java, I would be able to instantiate TableModel.java and passed an instance of MyTableModel during construction time.

Now it's working properly. My question is, I would like to enhance existing code to accept any click event within the table cells. Where should I put Listener class at? And what interface should be implemented by Listener class?
0
Comment
Question by:isuhendro
[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
  • 2
5 Comments
 
LVL 15

Expert Comment

by:Javatm
ID: 18754184
Here's how you do it, this one waits for a double click but you can customize it easily for a single click:
http://www.rgagnon.com/javadetails/java-0336.html
0
 
LVL 15

Accepted Solution

by:
Javatm earned 375 total points
ID: 18754190
> Where should I put Listener class at? And what interface should be implemented by Listener class?

On your table:
YourTable.addMouseListener(new MouseAdapter(){
     public void mouseClicked(MouseEvent e){
      if (e.getClickCount() == 2){
         // Do your stuff
      }
    }
} );
0
 

Author Comment

by:isuhendro
ID: 18754335
hi wizard,

thanks for your clue... i am trying your suggestion and able to trap the event.. but if i am not wrong this event is a kind of event that triggered by JTable object, by then can I trap the cell information as well?

I am trying using e.getX() and e.getY().. but the result of X,Y is just cell position in pixel unit, not the cell matrix information.

0
 

Author Comment

by:isuhendro
ID: 18754694
hi wizard,

i got to find these below to complete the solution on getting cell matrix information

table.getSelectedRow();
table.getSelectedCount();

Thank you.
0
 
LVL 15

Expert Comment

by:Javatm
ID: 18760838
I'm glad I was able to help
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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 …
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 learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

610 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