• 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 cell is selected but i want the entire row to be selected

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
i have a few fields which receive focus when i press Tab, beneath these fields i have a JTable. The first cell in the JTable receives focus when i press Tab and looses focus when i press Tab again. Instead of this single cell to be selected i want the entire row to be selected instead.
How can this be accomplished?
Thanks a lot!!
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this:
table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION)
Is that what you want? It might help to describe WHY you want the sort of behavior you're looking for.
 
Ling Chung
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well i have set the mode to single selection. What i want is when i tab through the different fields that once i have focus on the JTable it selects the first row. I have accomplished that it sets focus to the JTable only once (the first row) and then sets focus to one of the other fields, but it now only has focus on the first cell in the first row and not the entire row.

I want to have focus on the entire row when pressing tab to set focus on the JTable. I want this because then when i tab through my application and have focus on my JTable i can proceed by pressing the arrow down.
Hope this clears things??
Thanks for the help!!
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ling,
I think it would be a better approach to have your own implementation of ListSelectionModel and ListSelectionListener used in JTable. This would give you the flexibility to have your own way to implementing selecting stuff in the table.
-Dhanush
 
Ling Chung
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i have my own listselectionmodel, but how can i make it select an entire row if a single cell is selected(this is only the case when i get focus on the table by pressing Tab, othwerwise(mouseclick) is selects the entire row), or how can i make sure that when Tab is pressed an entire row is selected instead of a single cell.
Hope this makes my question more clear...
Please help me out on this one...

Thanks!!
[ April 20, 2004: Message edited by: Ling Chung ]
 
Ling Chung
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys please help me out on this one...

Thanks!!
 
maggie woo
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[the requirements seem so arbitrary, it reminds me of times when users tell the programmers how to program]
if you want to never allow a cell to be selected or have focus, it sounds like your table is not editable. let's go on that assumption.
however, you need the rows to be selectable in order to fire some event to do something related to the data in the row being selected.
but, you are snagged because when you hit tab to enter the table, instead of highlighting the whole row, it highlights the row and puts the focus on the first cell. and when you arrow down, the next row highlights, but the focus is still on the first cell.
but (let's fantasize for a moment) the row is correctly being "selected" and "highlighted" but the fact that one of the cells "has focus" is causing that cell to "seem selected", and that what you really want to solve is how to make it seem to the user that the row is the only thing selected, and not the cell.
how close is that to your problem? i'm just restating it because i can't understand your problem as you stated it--no point going down blind alleyways.
 
Ling Chung
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by maggie woo:
however, you need the rows to be selectable in order to fire some event to do something related to the data in the row being selected.


That's correct


but, you are snagged because when you hit tab to enter the table, instead of highlighting the whole row, it highlights the row and puts the focus on the first cell.


No it doesn't highlight the row only the first cell gets highlighted.


and when you arrow down, the next row highlights, but the focus is still on the first cell.


Yes when i arrow down the next row highlights, the first row didn't highlight. I want the entire first row to be selected(highlighted) when i enter the table by pressing TAB.


but (let's fantasize for a moment) the row is correctly being "selected" and "highlighted" but the fact that one of the cells "has focus" is causing that cell to "seem selected", and that what you really want to solve is how to make it seem to the user that the row is the only thing selected, and not the cell.


No that's not it i don't mind the cell seeming selected, all i want is when the user Tabs through the GUI, and when the Table gets focus for the first time that not just the first cell is selected, but the entire first row...
Sorry if it seems so unclear....
Thanks!!
[ April 22, 2004: Message edited by: Ling Chung ]
 
maggie woo
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm.. Ok, I'm probably out of my league here.
Just to backtrack a bit. If you just have a JTable with the DefaultListSelectionModel, and the mode set to SINGLE_SELECTION, when you tab in the table, it moves cell-to-cell, but when you arrow down or up, entire rows are selected. This is true--yes?
So, when you modified whatever you did to change the tab behavior, what did you change--maybe what you changed affected this?? And it's a matter of tracking that down...
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just remove the column selection property by going to the properties. And the whole row is selected
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
reply
    Bookmark Topic Watch Topic
  • New Topic