Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable customize : RowSelection

 
Stephen Wei
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTable look and feel.

Please send me any body having examples on JTable Look and Feel.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic