JDateChooser setEnabled Color

Discussion in 'Java' started by Biagio, Jun 5, 2011.

  1. Biagio

    Biagio Guest


    I'm using the powerfull JDateChooser JCalendar library 1.3.3.

    Unfortunately, when the component is setEnabled (false) the color of
    date is a gray almost unreadable.

    I tried to change color, but when the component is disabled is not
    possibile, it is always gray.

    I would like to get a look like JTextField.setEditable (false).

    Does anyone have any suggestions?


    Biagio, Jun 5, 2011
    1. Advertisements

  2. I assume you mean com.toedter.calendar.JDateChooser, found here:

    The color has nothing to do with JDateChooser; it is specified by the
    user interface default, which varies for each look and feel.
    Because JDateChooser has a com.toedter.calendar.JTextFieldDateEditor, a
    subclass of javax.swing.JFormattedTextField, you can set the disabled
    color of any particular instance:

    JDateChooser jdc = new JDateChooser();

    Alternatively, you can change the UI manager's default, but I'd be wary
    of veering too far from the familiar interface; it may be worthwhile to
    choose a color derived from the expected value.

    String name = "FormattedTextField.inactiveForeground";
    ColorUIResource color = (ColorUIResource) UIManager.get(name);
    UIManager.put(name, color.darker());

    As an aside, I was recently critical of the demo's layout:


    Line 132 in com.toedter.calendar.demo.JCalendarDemo is the problem:


    Simply remove it to allow pack() to do the right thing.
    John B. Matthews, Jun 5, 2011
    1. Advertisements

  3. Biagio

    Tom Guest

    Ah - didn't realise it was only the demo program you were unhappy about...

    Anyway, the aforementioned additions were:
    - nullText property - if the JDC's date is null then display any null
    text, for example "Open Ended"

    - selectOnFocus property - optionally select the text when the editor
    gets the focus

    - dateVerifier property - an interface that JDC calls back on to allow
    client code to indicate whether a date is selectable; calendar buttons
    are disabled for invalid dates and the editors skip to the next valid
    date in the "direction of travel"

    - use action map to (ctrl-c) popup the calendar; (ctrl-n) set to null

    - provide access to the DateFormat inside so you can (eg) set its timezone

    I'm in the process of pulling together other people's mods and will
    github all this soon...
    Tom, Jun 5, 2011
  4. Honestly, I didn't know either. :) It was just the first thing I ran
    across, and I feared it was an ill omen. Of course, the more I use it,
    the more I like it.
    The dateVerifier looked especially appealing, although I'd since
    reverted to the stock 1.3.3. It's clear you've worked with it
    extensively; I'd welcome any comment you have on my response to the OP.
    John B. Matthews, Jun 6, 2011
  5. Biagio

    Biagio Guest

    Thanks !!!!

    Biagio, Jun 6, 2011
  6. Biagio

    Tom Guest

    Looks like its gone down a storm...

    I'd agree that tweaking the UI defaults is not generally a good idea
    but that if you do, stick to the ones that are common (or at least always
    likely to be present) across all L&F you might be running under. If you
    want to see what UI defaults there are then I recommend Rob Camick's
    utility for browsing them:

    @Biagio - of course all your text fields will look the same when disabled,
    so your problem is not limited to JDateChooser's text field....
    Tom, Jun 6, 2011
  7. Biagio

    Roedy Green Guest

    I wrote a DateChooser. If it is defective, I will fix it as top
    priority. If you want something eccentric, you have the complete
    source code.

    See http://mindprod.com/products1.html#SPINNER
    The class you want is called DateSpinner.

    You can see it in use at http://mindprod.com/applet/canadiantax.html
    or http://mindprod.com/applet/bio.html

    Roedy Green Canadian Mind Products
    How long did it take after the car was invented before owners understood
    cars would not work unless you regularly changed the oil and the tires?
    We have gone 33 years and still it is rare to uncover a user who
    understands computers don't work without regular backups.
    Roedy Green, Jun 7, 2011
  8. Biagio


    Sep 8, 2011
    Likes Received:
    set JDateChooser not editable


    private com.toedter.calendar.JDateChooser dcStart;
    private com.toedter.calendar.JDateChooser dcEnd;
    to make dcStart not editable:


    to make the Background white:

    I hope this will help!

    meziano, Sep 8, 2011
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.