How to deploy the Toedter JCalendar

Hi all,
stupid, but only after a long time I decided to deploy the JCalendar by Toedter to enter
dates or to confirm default dates.
However gorgeous the doc's and the demo are, I can't find out how to use it in my code.
I can't find a way to add an ActionListener or whatever.
Has anybody a simple coding example?

All I want for now is:
1) put the control in my frame,
2) preset a default date,
3) be alerted when a date is chosen,
4) get the new date to my program.

;JOOP!
LVL 24
sciuriwareAsked:
Who is Participating?
 
ADSLMarkConnect With a Mentor Commented:
I didn't know of the existence but..

import java.util.*;
import javax.swing.*;
import java.beans.*;
import com.toedter.calendar.*;

class JDC extends JFrame implements PropertyChangeListener
{
    public JDC()
    {
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        this.setSize(800,600);

        JDateChooser dc = new JDateChooser(new Date());
        dc.addPropertyChangeListener(this);
        this.getContentPane().add(dc);
    }

    public void propertyChange(PropertyChangeEvent pce)
    {
        if(pce.getPropertyName().equals("date"))
            System.out.println(pce.getNewValue());
    }

    public static void main(String[] args)
    {
        JDC jdc = new JDC();
        jdc.setVisible(true);
    }
}

Looks like what you want?

Mark
0
 
CEHJCommented:
Very strange - it seems to have been made unobservable. I'd be inclined to override

public void propertyChange(PropertyChangeEvent evt)

of JCalendar
0
 
ADSLMarkCommented:
I believe it is customary to have propertyChange overriden when using netbeans, no? Anyway, I made this example using the existing demo in the JCalendar package.. so it seems this is the way.

Mark
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
sciuriwareAuthor Commented:
Not exactly but it is a start.

When I run with the provided source it crashes.
When I run with the provided .jar it works, but,
when I change JDateChooser to JCalendar it says it can't resolve JCalendar .....

;JOOP!
0
 
sciuriwareAuthor Commented:
And it looks terrible anyway.

;JOOP!
0
 
CEHJCommented:
>>when I change JDateChooser to JCalendar it says it can't resolve JCalendar .....

Can you post how you did that?
0
 
sciuriwareAuthor Commented:
See the code above and
replace:

        JDateChooser dc = new JDateChooser(new Date());

by

        JCalendar dc = new JCalendar(new Date());

;JOOP!
0
 
ADSLMarkCommented:
"And it looks terrible anyway."

Haha, what did you expect? A fully working application which was precisely what you wanted? You wanted some example material.. and i gave precisely that what you requested. It's ok if you do not want to use it or think it's rubbish, it was just some quick code anyway.

Mark
0
 
sciuriwareAuthor Commented:
ADSLMark, can you run your example yourself, it doesn't quite look like teodters pictures.

;JOOP!
0
 
ADSLMarkCommented:
Seems you do not understand the idea behind "a-push-in-the-right-direction".

Please do not comment on everything I say, just wait for someone else to give you a complete implementation with all the fuctionality you had in mind.
0
 
sciuriwareAuthor Commented:
You are over-reacting.
The samples by Toedter show a single JCalendar component that you can click on.
I don't blame you for not knowing how to solve this.

It's just remarkable that this tool has been mentioned for years
but the deployment seems to be a riddle.

;JOOP!
0
 
ADSLMarkCommented:
Sorry, I really do not understand your problem. I downloaded the file at:

http://www.toedter.com/download/jcalendar-1.3.2.zip

and extract the content to disk. I went into the src directory and found in "com/toedter/calendar/demo" a very nice demo, showing the use of all the controls etc.
Just like the one demo on the website:

http://www.toedter.com/en/jcalendar/demo.html

So what is your problem really?
For the actionlistener, you have to use propertylistener and add that to the datechooser or whatever. Just add some System.out.println() to the propertyChanged() method and see what events are triggered when performing an action.

I do not understand why you can't get what you want. It really isn't that difficult. I thought I show you a very very simple example, which has only the essential code, without all layout issues etc. You thought it was rubbish, well fine, but the next possible example is already available to you..

If you want me to give you sth which looks more like you want, then give a better specification or post some sample code on how you want it to work and we can change your code in such way that it really works.

Good luck.
Mark
0
 
sciuriwareAuthor Commented:
Rubbish is YOUR word, not mine.

In the demo you can click an icon which starts a JCalendar and which
puts the chosen date into a textfield.
The sources are such that I first asked if someone already had found out.
Digging in somebody elses sources is not my hobby.

All I was looking for was the control? that looks like a textfield and which launches the JCalendar.

Btw.: I got the JCalendar working now and I get 2 events for one date, which I get by .getDate();

;JOOP!
0
 
sciuriwareAuthor Commented:
ADSLMark, I'm sorry I made a few stupid mistakes.
Your initial code works perfectly like the demo does.
The only thing I had to add was to set a date format beginning in a space and ending an extra space,
because setting the size to one that displayed the full date did not seem to work.

And please don't lose your temper when someone with 400000 points proves to be human too.

;JOOP!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.