aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Date Editor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Date Editor " Watch "Date Editor " New topic
Author

Date Editor

Giuseppa Cefalu
Ranch Hand

Joined: Jul 15, 2011
Posts: 121
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

Joined: Jul 15, 2011
Posts: 121
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

Joined: Oct 16, 2003
Posts: 1096
    
  10

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.

Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Giuseppa Cefalu
Ranch Hand

Joined: Jul 15, 2011
Posts: 121
Coud you post your modified sample?
Giuseppa Cefalu
Ranch Hand

Joined: Jul 15, 2011
Posts: 121
Hi there,

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

Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1096
    
  10

ok, cool. And if you can change the topic to 'resolved' status, that would be cool too!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date Editor