Luis Fernando Flores
Luis Fernando Flores

Reputation: 21

JDateChooser make action when you select date automatically only one time

the thing is that i'm using in Customize Code the next code:

DachBuscar.getDateEditor().addPropertyChangeListener(new java.beans.PropertyChangeListener(){
    public void propertyChange(java.beans.PropertyChangeEvent evt){
        System.out.println("Hello World");
    }
});

but when i do click on the JDateChooser and i select the date, it make the action 5 times and of corse that is slower because i'm using an sql consult and that method is used 5 times, i only want to make that code 1 time, and also i thing the number of times that the method execute its more and more because i try to patch this with if and a int variable increasing each time that the method execute to use it only one time but it doesn't make effect

Upvotes: -2

Views: 1330

Answers (2)

Omar Guermoudi
Omar Guermoudi

Reputation: 11

JDateChooser chooser = new JDateChooser();

chooser.getDateEditor().addPropertyChangeListener(
    new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent e) {
            if ("date".equals(e.getPropertyName())) {
                System.out.println(e.getPropertyName()+ ": " + (Date) e.getNewValue());
            }
        }
    });

this.add(chooser);

Upvotes: 1

I think your DachBuscar.getDateEditor().addPropertyChangeListener getting called multiple times,Make sure whether your method called only once.

Upvotes: 0

Related Questions