Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Prevent selection of certain JTable cells

 
Nicholas van Orton
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic