[Microba-controls] commitEdit of a null Date value
Brought to you by:
michaelbaranov
From: Chris M. <ch...@st...> - 2007-10-15 22:31:08
|
Hi Michael, I found something for your consideration, which has required changing the microba source as configuration was not possible. The problem is that JFormattedTextField does not properly support the concept of a null date. A null date can't be committed (commitEdit()) to a JFormattedTextField. As you can see from the code Sun's bug database offers a workaround that I've implemented on your code. This code is from changes I've made to BasicDatePickerUI: private DefaultFormatterFactory createFormatterFactory() { return new DefaultFormatterFactory(new NullCapableDateFormatter(peer .getDateFormat())); } /** * To do this enhancement: * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4745048 */ public class NullCapableDateFormatter extends DateFormatter { public NullCapableDateFormatter(DateFormat dateFormat) { super( dateFormat); } public Object stringToValue(String string) throws ParseException { if(string == null || string.length() == 0) { return null; } return super.stringToValue(string); } } thanks - Chris |