• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable customize : RowSelection

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JTable look and feel.

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