• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date Editor

 
Giuseppa Cefalu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My DateEditor returns a string; The first code block installs the editor and overrides it to return a string instead of a date. The problem is that it affects the String.class columns as well as the java.sql.Date columns. I can manage this by creating an editor for the string that uses a masks and does not include the "-" date formate character. However, I wonder if there is a way to make the date editor specific to Date columns. May be, casting the date string to date and having the editor returning a date type instead of a String? Is there any way to do this? It seems complex for the case where the returned value is null. Any ideas on how to do this? Thank you.




This is the editor



 
Giuseppa Cefalu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thing is that if I want for my dates to be editable I have to return a String in getColumnClass(int col) method; therefore the editor has to be installed with String.class input. If I return Date in getColumnClass and install the editor with Date.class input, the cell is not editable; and it makes sense because the editor formats a string gets a string from getText() and returns a string. The only solution I see is to create a mask editor for the strings; this works; but I do not understand why. What am I missing?

 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I copied your code and made some modifications and it works for me.
1) First of all, the call to setting the editor can be simple. I don't understand why you loop through and set it in a complicated way. I have done this:


where DATE_FIELD is a constant(int) pointing to the column number.

2) I see that in the getColumnClass, you are making a decision based on the type. I have changed it to make it based on the column number. If you can follow a similar/simpler mechanism, that should work for you.

Note that, I have used the rest of the code as it is (including the editor, DateField, DateDocument) and it works fine for me.
 
Giuseppa Cefalu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Coud you post your modified sample?
 
Giuseppa Cefalu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

Thank you for your reply. I am using the code below and it works fine now.

 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, cool. And if you can change the topic to 'resolved' status, that would be cool too!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic