• 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 Selection Depends On Editable Cells

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic