Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2005

Tip: Looking for answers? Try searching our database.

JTable and editing

Thread view: 
Jan Danielsson - 01 Jan 2005 23:09 GMT
Hello all,

I would like to be able to double click on a row in a JTable, which
would brings up a dialog which allows the user to edit some of the
variables associated with the row selected (read: the double clicked row).

I know how to create a JTable, and use it. I also have the dialog code
ready, but not the connection between them. How do I detect a
double-click in the JTable, and how do I find out which cell (read: row)
has been the target of the click?

Signature

Kind regards,
Jan Danielsson
No one loves a cynic

Andrew McDonagh - 01 Jan 2005 23:18 GMT
> Hello all,
>
[quoted text clipped - 6 lines]
> double-click in the JTable, and how do I find out which cell (read: row)
> has been the target of the click?

Add a custom TableCellEditor object to the table. When its called, it
can show the dialog.

http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/table/TableCellEditor.html
Chas Douglass - 02 Jan 2005 00:31 GMT
> Hello all,
>
[quoted text clipped - 7 lines]
> double-click in the JTable, and how do I find out which cell (read:
> row) has been the target of the click?

table.addMouseListener(MouseAdapter() {
 public void mouseClicked(MouseEvent event) {  
   if (event.getClickCount() == 2) {
     Point clickPoint = event.getPoint();
     int row = table.rowAtPoint(clickPoint);
     int column = table.columnAtPoint(clickPoint);
     if (row != -1 && column != -1) {
       // dialog goes here
     }
   }
 }
});

You're free, of course, to ignore the column if all you are interested in
is the row.

Hope that helps.

Chas Douglass


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.