• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Prevent selection of certain JTable cells

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Do not threaten THIS beaver! Not even with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic