• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

JTable Double click

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to know how to capture the double click event on a JTable
Here is what I used for a single click:
m_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionModel rowSM = m_table.getSelectionModel();
rowSM.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
//Ignore extra messages.
if (e.getValueIsAdjusting()) {
return;
}
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
if (lsm.isSelectionEmpty()) {
System.out.println("No rows are selected.");
}
else {
int selectedRow = lsm.getMinSelectionIndex();
System.out.println("Row " + selectedRow + " is now selected.");
// Display data from column
//selected
System.out.println((String) m_table.getValueAt(m_table.getSelectedRow(), m_table.getSelectedColumn()));
// Display data from first
column of select row
System.out.println((String) m_table.getValueAt(m_table.getSelectedRow(), 0));
}
}
});

What I am realy looking for is the first column's data of the double clicked row.
Thanks
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure if you want to try mouseListener. Here is some code in my project. I hope it can solve your problem.
yourTable.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent me) {
JTable table =(JTable) me.getSource();
Point p = me.getPoint();
int row = table.rowAtPoint(p);
int col = table.columnAtPoint(p);
if ((col == 0) &&(me.getClickCount() ==2) ) {

// stop table editing and get your data..
}
}
});
good luck!
 
Dean Reedy
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankyou the mouse listner works, but it only works if I double-click on the first column (0). Is there anyway to double click also on the other columns?
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dean,
How about using Renees' code and removing the following:
( col == 0 )
Just a thought ...
Manfred.
 
Dean Reedy
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Everyone,
Thanks! That did it, I was no paying attention. I appreciate it!
Dean Reedy
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic