Get rid of all com.toedter.calendar.JDateChooser colors

200 Views Asked by At

My humble goal is to have a date-picker in java swing that does not have hard-coded colors in it. A date-picker that delegates it's appearance to the chosen LAF.

Sob...

I am using com.toedter.calendar.JDateChooser version 1.4

With this answer i was able to get rid of green and red and black of the jtextfield.

Java Jdatechooser Foreground

With this, i was able to remove other annoying colors:

myDC.getJCalendar().setWeekdayForeground(null);
myDC.getJCalendar().setDecorationBackgroundColor(null);
myDC.getJCalendar().setSundayForeground(null);

Now i am stuck with the year spinner and it's unwanted colors. See:

enter image description here

enter image description here

Any clue on how to get rid of those?

1

There are 1 best solutions below

13
trashgod On

The effect illustrated is a feature of the CaretListener implemented by JTextFieldDateEditor and the JYearChooser parent class, JSpinField. Omit the addition of the listener to eliminate the effect; in outline:

public JTextFieldDateEditor(…) {
    …
    //addCaretListener(this);
    …
}
public JSpinField(…) {
    …
    //textField.addCaretListener(this);
    …
}

Less radically, it is also possible to invoke removeCaretListener() on the editor.

Calendar c = Calendar.getInstance();
JDateChooser jdc = new JDateChooser(c.getTime());
JTextFieldDateEditor editor = (JTextFieldDateEditor) jdc.getDateEditor();
editor.removeCaretListener(editor);

Also override the caretUpdate() method inherited by JYearChooser to condition the effect based on a suitable boolean value.

JYearChooser jyc = new JYearChooser() {
    boolean update;

    @Override
    public void caretUpdate(CaretEvent e) {
        if (update) {
            super.caretUpdate(e);
        }
    }
};