wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JTable customize : RowSelection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable customize : RowSelection" Watch "JTable customize : RowSelection" New topic
Author

JTable customize : RowSelection

Stephen Wei
Ranch Hand

Joined: Oct 09, 2001
Posts: 73
Hello everyone:
I am creating a JTable, for which when user clicks a cell in the first column, the whole row will be selected, when user clicks any cell in other columns, only the single cell will be selected. Can someone please sugguest me a good approach to do this?
I think that I may disable Row selection by
jTable1.setRowSelectionAllowed(false);
then use a cell renderer or listener for the first column, and enable RowSelection everytime the user chooses cell from first column. ...
I think it is not so easy to implement, can someone suggest me a clean way to solve my problem?
Thanks


Sun Certified Programmer for Java Platform
Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
I also have the same requirement and also facing the same prob. I am trying the following approach
1. Added mouse listener to JTable
2. Identified on which cell the mouse click happened.
Here's the code
public void mouseClicked(MouseEvent e)
{
if ( getSelectedColumn() != 0 )
{
//clearSelection();

setRowSelectionAllowed(false);
setCellSelectionEnabled(true);
repaint();
}
else
{
setCellSelectionEnabled(false);
setRowSelectionAllowed(true);
repaint();
}
}
However, in my table I always have a blank row as the last row. When insert few rows in table, the blank row appears always at the last. Under such situation, when I select a non blank cell, just above the blank cell, the blank cell also gets selected. I dont know how to deal with this problem. I also dont know whether I am right in my approach.

Can anyone please help me with this ?

Waiting for your reply

Thanks and Regards
Rohit.
[ January 29, 2007: Message edited by: Rohit Bhagwat ]
Naveen Kumar
Ranch Hand

Joined: Dec 14, 2006
Posts: 35
JTable look and feel.

Please send me any body having examples on JTable Look and Feel.
 
wood burning stoves
 
subject: JTable customize : RowSelection