Solved

How to deploy the Toedter JCalendar

Posted on 2006-11-19
14
1,580 Views
Last Modified: 2007-12-19
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!
0
Comment
Question by:sciuriware
  • 7
  • 5
  • 2
14 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Very strange - it seems to have been made unobservable. I'd be inclined to override

public void propertyChange(PropertyChangeEvent evt)

of JCalendar
0
 
LVL 10

Accepted Solution

by:
ADSLMark earned 500 total points
Comment Utility
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
 
LVL 10

Expert Comment

by:ADSLMark
Comment Utility
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
 
LVL 24

Author Comment

by:sciuriware
Comment Utility
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
 
LVL 24

Author Comment

by:sciuriware
Comment Utility
And it looks terrible anyway.

;JOOP!
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>when I change JDateChooser to JCalendar it says it can't resolve JCalendar .....

Can you post how you did that?
0
 
LVL 24

Author Comment

by:sciuriware
Comment Utility
See the code above and
replace:

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

by

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

;JOOP!
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 10

Expert Comment

by:ADSLMark
Comment Utility
"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
 
LVL 24

Author Comment

by:sciuriware
Comment Utility
ADSLMark, can you run your example yourself, it doesn't quite look like teodters pictures.

;JOOP!
0
 
LVL 10

Expert Comment

by:ADSLMark
Comment Utility
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
 
LVL 24

Author Comment

by:sciuriware
Comment Utility
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
 
LVL 10

Expert Comment

by:ADSLMark
Comment Utility
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
 
LVL 24

Author Comment

by:sciuriware
Comment Utility
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
 
LVL 24

Author Comment

by:sciuriware
Comment Utility
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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scoreUp challenge 14 48
countAbc challenge 9 49
firstChar challenge 13 83
eclipse package explorer vs project explorer view 2 27
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now