Donate Share

Microba controls

Tracker: Bugs

5 Cannot manually enter null date (in the textfield) - ID: 1950700
Last Update: Comment added ( metal_max )

To reproduce:

1. create a form that contains DatePicker component
2. click the calendar button and select any date
3. in the textfield, erase the date
4. call commitEdit(); it returns false; does not set the internal Date
variable to null
5. call getDate(); it returns the last valid date selected in the calendar
component rather than null


Nobody/Anonymous ( nobody ) - 2008-04-24 13:17

5

Open

None

Nobody/Anonymous

None

None

Public


Comments ( 2 )




Date: 2009-11-19 09:23
Sender: metal_max

Another similar solution that does not depend on JGoodies:

/**
* Customized DatePicker UI delegate object that sets the date value to
null if
* the textfield is empty or contains solely whitespace
*/
public class MyDatePickerUI extends BasicDatePickerUI implements
FocusListener {
static {
UIManager.put("microba.DatePickerUI", "MyDatePickerUI");
}

public static ComponentUI createUI(JComponent c) {
return new MyDatePickerUI();
}

@Override
protected void installComponents() {
super.installComponents();
field.addFocusListener(this);
}

public void focusGained(FocusEvent e) {
// No additional behavior
}

public void focusLost(FocusEvent e) {
if (((JFormattedTextField)e.getComponent()).getText().trim().equals(""))
{
((JFormattedTextField)e.getComponent()).setValue(null);
}
}
}


Date: 2008-08-19 12:49
Sender: nobody

Logged In: NO

I have a solution for that problem

Override the BasicDatePickerUI

public class MyDatePickerUI extends BasicDatePickerUI {

public static ComponentUI createUI(final JComponent c) {
return new MyDatePickerUI();
}

/** {@inheritDoc} */
@Override
protected void installComponents() {
super.installComponents();
field.setFormatterFactory(new DefaultFormatterFactory(
new EmptyDateFormatter(peer.getDateFormat())));
}

}
And reset the formatter on the field. Use the EmptyDateFormatter from
JGoodies that returns a null value when an empty string is entered.

//change the UIManager
new MicrobaComponent(); //you have to do this, because the first time a
MicrobaComponent is created the Microba.init() is called in a static
constructor
UIManager.put("microba.DatePickerUI",
"xxx.xxx.MyDatePickerUI");



Log in to comment.

Attached File

No Files Currently Attached

Change

No changes have been made to this artifact.