wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JTable Selection Depends On Editable Cells Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable Selection Depends On Editable Cells" Watch "JTable Selection Depends On Editable Cells" New topic

JTable Selection Depends On Editable Cells

John Smith
Ranch Hand

Joined: Jul 20, 2001
Posts: 84
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...
John Smith
Ranch Hand

Joined: Jul 20, 2001
Posts: 84
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

Joined: Jan 07, 2002
Posts: 89
You can also set the selection mode of the table to single row selection...like this:
JTable table = new JTable(<add model, etc> ;
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 Wisard<br />Sun Certified Java Programmer (Java 2)<br />Sun Certified Web Component Developer
jQuery in Action, 2nd edition
subject: JTable Selection Depends On Editable Cells
Similar Threads
JTable Cell
JTable selection problem
Update Jtable
getting focus in one cell in JTable