Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable Selection Depends On Editable Cells

 
John Smith
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi There,
When I single click a cell in a JTable which is not editable, the cell is painted blue. When I click a cell which is editable, a blue border appears around the cell, but the cell itself remains white. Does anyone know how to alter this behavior? I want an editable cell to look like a non-editable cell when it is clicked (I want everything painted blue when clicked - not just the border). When you click on a cell and it isn't painted blue, it gets confusing (people think it's not selected).
I have a feeling this is related to the CellRenderer's. For an editable cell it may be a TextField (when clicked only the border is shown) and a non-editable cell may have a JLabel (when clicked the entire thing is painted). I may be wrong about this though. Thanks for any help...
Randy
 
John Smith
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I answered my own question. In case any one is interested, I simply created my own renderer (which extended from DefaultTableCellRenderer) which basically used the same code for GetTableCellRendererComponent() as the DefaultTableCellRenderer except I got rid of these lines of code:

[ January 12, 2002: Message edited by: Randy Gordon ]
 
Jeff Wisard
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also set the selection mode of the table to single row selection...like this:
JTable table = new JTable(<add model, etc> ;
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
When you click on a row after doing this, the entire row is selected, with no distinction between the row and the cell you selected.
-Jeff
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic