The value of jDateChooser is back to the default value - java

I'm using jDateChooser in NetBeans, when i run the program and choose any date, it is not choosing correctly.
For example, if i choose 05-05-2020, it shows 29-12-2018.
Also, if it catch the selected date, when i press on another item (any button or text field), the Date back to its default.
I didn't add any code related to it, only take it from tools box and put it on the Frame.
What is the problem?

The problem was that i am using wrong date format, it was YYYY-MM-dd, the correct one is yyyy- MM-dd

Related

Customize Android CalendarView - Display DropdownMenu

I have a project where I use a CalendarView, the built in Calendar for android.
So, I'm facing some difficulties to achieve some specific tasks for this Calendar. And I really hope I can find the solution here on StackOverflow.
Is there any possible way of setting each day on a onClickListener?
If not, Then stop reading.
This is the problem I have:
I would like to display a dropdown menu from the selected day, with a few elements that the user can select. If the user select some element, than the state will change for the dropdown menu ONLY for the selected date i.e. if user click on 13/1 the dropdown should display 10 elements. If user select one value, "lunch", then the dropdown menu must change so if user click again only "lunch" and "delete" will appear, not the other 9 elements which were displayed from first user interaction.
The problem I have here, is that the dropdown menu is connected to ALL dates, so I believe I need a onClickListener for each date in the calendar, therefore I wonder if it is possible.
I have been struggling with using different libraries from the internet, especially from GitHub without any success so I hope there's a way of achieve this via the built-in calendar.
Best regards
Is there any possible way of setting each day on a onClickListener?
Yes.
Try this way, In your onClickListener,
1. You need calendar instance.
Calendar calInstance=Calendar.getInstance();
2. SimpleDateFormatter required.
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
3. Create a Date Object
Date date = new Date();
4. Create string to store current date on each click listener.
String currentDate=sdf.format(date);
5. Perform your required operations on this currentDate that you have received.

Unable to select date in datepicker

I'm testing a widget where I have to enter a start and end date using a calender. In real life use I select the option to enter dates from a drop down, a calender then appears where I have to click a start and an end date. Only after I click on 2 days the date fields are filled. I have no problems doing this manualy but automating the test is proofing difficult. Here's a few screenshots to illustrate what I'm trying to do. After selecting the option to enter dates the following screen appears:
Here I first click the From day (24), followed by the To day (31). Right after I click 31 the calender dissappears and the two date fields are filled with my selection:
I'm trying to automate this with the following code:
driver.findElement(By.xpath(".//span[#class='DateRangePicker__DateLabel'][contains(text(), '24')]")).click();
driver.findElement(By.xpath(".//span[#class='DateRangePicker__DateLabel'][contains(text(), '31')]")).click();
Here's part of the code I'm basing this on:
<span class="DateRangePicker__DateLabel" data-reactid=".0.1.1.0.1.1.1.0.0.2.0.1:$0-2016-4.1.1.$4.$1.2">24</span>
The code does not fail but the dates are not selected either.
using datepicker in selenium - LINK
You could inspect id of from and to field. THen execute this command using javascript
$('#id').datepicker("setDate", "date_you_want_in_right_format")
Note 1: You need to follow strictly date format that allowed by datePicker
Note 2: Tested with https://jqueryui.com/datepicker/
$('#datepicker').datepicker("setDate", "03/15/2016")

sendKeys() not working in Date or Time edit boxes in Selenium Code

In Selenium Javascript, sendKeys() is not working in Date or Time edit boxes. When I use the below code, it didn't populate the values in the appropriate fields. Is there any alternate for sendKeys()?
String strDate = "10/10/2014" ;
driver.findElement(By.xpath(DateXpath)).sendKeys(strDate);
Even I tried by hard coding the value inside sendKeys(), like
driver.findElement(By.xpath(DateXpath)).sendKeys("10/10/2014");
but didn't work
sendKeys works when that field is clicked once, before entering value, Code as follows,
driver.findElement(By.xpath(DateXpath)).click();
driver.findElement(By.xpath(DateXpath)).sendKeys("10/10/2014");
Does the date box have a format displayed in it? Something like dd/MM/YYYY. If that is the case it is possible that while selenium is trying to enter values in the date field, the javscript for that date format is still running. so whatever values you enter via selenium gets very quickly over written by date format provided by javascript making it appear like your date value was never entered. You can try putting a simple delay before entering the date value.

Java: How to set value of one JDateChooser to another JDateChooser?

I have two JDateChoosers, One with label 'Start Date' & another with 'End Date'.I have two radio buttons 'single Day' & 'Multiple Day'.If I select 'Single Day' I want to display same date to 'End Date' which selected in 'Start Date'. And I also want to clear these JDateChooser fileds on CLEAR_BUTTON_CLICK.How do I write this? I am using this control first time..
Plz,help me..
Thanks in advance..
I'm assuming that you are talking about JDateChooser from JCalendar. Am I correct? The JDateChooser fires a PropertyChangeEvent when its date is changed. So, to set the date of another JDateChooser, you need to add an event handler to the "source" component to deal with the change event. When it is fired, you take the date of the component using getDate() method and set it to the target component, using setDate() method. As you are using a component suite that I don't have installed here, it is difficult to implement a correct solution to you.
Take a look in the docs: http://www.toedter.com/en/jcalendar/api/com/toedter/calendar/JDateChooser.html
I think that reading this you will be able to do what you want.
Edit: Here is some code. Try to use it. I really don't have certain that it will works since I didn't test it.
// sourceDateChooser and targetDateChooser MUST be final,
// since they will be accessed inside a anonymous inner class
sourceDateChooser.addPropertyChangeListener( new PropertyChangeListener(){
#Override
public void propertyChange(PropertyChangeEvent evt) {
// the docs of JDateChooser says that when the date is modified, a "date" property change is fired
if ( evt.getPropertyName().equals( "date" ) ) {
targetDateChooser.setDate( sourceDateChooser.getDate() );
}
}
});

Date Time Picker like in Windows

I am looking for a component for Swing that would do the same thing that Windows 7 date and time pickers do (or be even better). They look so:
And have following features I need:
you cannot enter an invalid value (value is ignored as you type and not when you leave the field)
it allows continuous updating of the field until the first change made by user (take a look on the time setting in Windows 7)
you can select and change at once only one position - not the whole text at once (so colons and points cannot be removed)
up and down buttons
calendar button (but it's rather optional for me)
I have tried JSpinner with a DateEditor but it doesn't have this features. JXDatePicker only adds the calendar button.
Generally I am looking for a nice way to let user enter date and time in a powerful and simple way. Windows 7 solution seems to be quite good.
Thank you!
best and free DatePickers around are JXDatePicker and JCalendar, in both cases are there focus about correct implementations of Date and Focus workaround, and excelent Renderer and Editor for JTree / JTreeTable / JTable
to your needs ---> all these funcionalities are implemented by default, not clear from your questions exactly whats wrong, I'm Win7 and JXDatePicker and JCalendar but I never saw these issues,
in both cases you have to implementing own workaround for SpecialDays as hollydays (and etc),

Categories

Resources