wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Prevent selection of certain JTable cells Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Prevent selection of certain JTable cells" Watch "Prevent selection of certain JTable cells" New topic
Author

Prevent selection of certain JTable cells

Nicholas van Orton
Greenhorn

Joined: Aug 13, 2005
Posts: 17
Hi folks,

At the moment, I'm putting together a date picker using a JTable, which looks something like this:



I'm not all that familiar with JTables, but I was just wondering if there is any way of preventing the blank cells (those that .equal("") in their respective arrays)?

Also, if a variable:

int date = 6;

was used to represent today's date, is there any way of searching through all the cells & selecting the cell that contains that value?

Any help with this would be very much appreciated.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Here's an event-oriented solution. Another (untried) possibility is to write a cell renderer and, for the empty cells, do not show any changes for selection or focus. The cell would continue to be both selected and the focus owner; you just would not have any visual indication. Or, you could do both. Even tough this (event) approach removes the focus, the cell renderer still seems to consider the cell to have focus: cover and uncover the table to see the restored appearance-of-focus. Press the tab key to remove it.
Nicholas van Orton
Greenhorn

Joined: Aug 13, 2005
Posts: 17
I see what you mean, this may just be a limitation on using a JTable?

Is there anyway to use the removeMouseListener() method on a JTable cell?
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
this may just be a limitation on using a JTable?
possibly
Is there anyway to use the removeMouseListener() method on a JTable cell?
Not exactly. But you could try something creative as an alternative.
I tried overriding processMouseEvent in the JTable and it seemed to work but every now and then it failed. I was unable to find out who was getting around the processMouseEvent method.

Then I tried a GlassPane and it seems to work okay.
 
 
subject: Prevent selection of certain JTable cells
 
Similar Threads
Very Very New
Problem with BoxLayout and JTextField
help with application variables to store the list of names code
convert Vector to xml
Displaying Table