Ok so say I'm doing an event scheduler and i have 3 combo boxes, first combo box is the month, the second is the date, and the third is the year. Is it possible using the Date Object in Java to have it automatically fill the options that you can select from?
The DateFormatSymbols class can be used to get the names of months you can use to fill in the combobox.
String months[]=(new DateFormatSymbols()).getMonths();
Don't forget that Java's months start with 0=January
The Calendar class can be used to determine the number of days in a given month, as well as the current year.
Calendar cal=Calendar.getInstance()
cal.setTime(System.currentTimeMillis() );
cal.set(Calendar.MONTH, Calendar.FEBRUARY);
int days=cal.getActualMaximum(Calendar.DAY_OF_MONTH);
Why do you want to use Date object to do that? if your goal is to fill all the months, days and several years in combo boxes then you can just add them directly in JCombo by using combo.addItem("<string value"). Hope this helps...
yes that possible, but that will be too hard job to synchronize all three JComboBoxes correctly for valid Year + Month + Day
if not Custom JCalendar (suggestion from your last post), then maybe JSpinner
Related
I'm trying to make a calendar, in which the days are in a RecyclerView.
I want to show the first day of the month on the column of the day of the week it starts on.
Is there a way to shift the items so that the first item starts on the right column?
Attached picture explains what I need.
You shouldn't care about the position in the column based on the day of the week.
One way is to have one Date instance for each day. To show one year in the above form you need to have a gridview 7x52. First cell in the gridview will have the first day of the year. The second day will go to the second position etc.. You can also extract from that the day of the month to produce the result you want.
You will need headers for that. Check this http://blog.sqisland.com/2014/12/recyclerview-grid-with-header.html
One way to create days for the adapter of your grid:
For every day out of the 365 {
Calendar newDay = Calendar.getInstance();
newDay.set(Year, 2016);
newDay.set(Calendar.Day_Of_Year, 0<i<365);
Arraylist adaptersData.add(newDay);
{
I have searched in google and hunted in stackoverflow.com for a particular solution. The problem is that, I want to create a custom date picker. The date picker dialog will open up on click of a button with a custom tile bar and maybe a custom background. The most important customization will be the years showing up in the picker. What I want to do is, I will allow the users to select a date which is minimum 18 years old from today and it can go up to a maximum of 50 years. I have seen solutions to this problem which suggests to use view.updateDate on the datepicker to reset the datepicker inside the date range if the user tries to select anything out of the range. But, I do not want to even show the years which are not in the range. I only want the users to see the valid years from which he can select. The rest of the years should not even show up.
How can I customize the datepicker to give me the desired output?
Thhis one will helpfull to you.
DatePickerDialog dp = new DatePickerDialog(this,
datePickerListener, year, month, day);
long maxDate;
Date newDate = c.getTime();
dp.getDatePicker().setMinDate(newDate.getTime());
dp.getDatePicker().setMaxDate(maxDate);
Is it possible to select multiple days in toedter's JCalendar? Like I would be able to highlight 2 or 3 days in the calendar and then get the days highlighted after I would trigger an event using a button.
or should i be better off using a JTable for a calendar?
I'd use a one column JTable having a JDateChooserCellEditor and a custom renderer. DemoTable is an example, seen here. The TableModel should contain a List<java.util.Date>, as Date implements Comparable for easy sorting. You can supply an addRow() method in DemoTableModel, which can be invoked in your Add button's handler.
I've got a DateTime (SWT.TIME) and want to know if the hours or minutes or seconds are selected.
I would like to get this information because I want that the User can scroll the mouse wheel in order to change the selected values accordingly.
Unfortunately I couldn't find any way to get the selected element of the DateTime Control. Does anybody have an idea?
DateTime provides many methods for getting the selected date. Like getHours, getMinutes, getDay, and so on. It's unclear to me what's your exact question, but appropiate setters are there as well.
I want to implement a date chooser using a JSlider. The user should be able to use the slider to freely choose between two previously known dates. I've seen examples like this one:
But I want to do the same, using only one slider. The minimal distance between two points (tick) should be one day. Any hints how to implement that?
If you want to have a slider with min = 1.1.2012 and max = 10.1.2012 just create a slider with min = 0 and max = number of days in between, then add the selected number to 1.1.2012.
I assume 10.1.2012 means January 10th, thus your slider would have min = 0 and max = 9. Then set the labels accordingly.
I can't to image how to do that with one JSlider, because there you'd have bunch of days, there are some workarounds for Double/RangeSlider, but I think better and easiest would be implements JSpinner with SpinnerDateModel, or best options is look for Custom Java Calendar or DatePicker
EDIT (#Robin)
First to answer your question: you can just use a JSlider, use the number of days between your start and end date to determine the range, and use custom labels (by using for example the setLabelTable method)
Now for user-friendliness, avoid this since
Nobody is familiar with this concept. Every site/application nowadays uses a textfield, most of the time in combination with a calendar widget. That is what users expect, not a slider
It will be hard to get all dates as labels on the slider due to the limited width. This means that a user have to interpolate / count to select his correct date
If you stick to the slider approach, at least consider to add a textfield as well. Even a non-editable text field which shows the currently selected date would be a huge improvement over a slider (see point 2)