GhostDZ9
GhostDZ9

Reputation: 155

How do I auto fill combo boxes? java

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?

Upvotes: 0

Views: 1164

Answers (3)

Brianorca
Brianorca

Reputation: 216

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);

Upvotes: 1

mKorbel
mKorbel

Reputation: 109813

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

Upvotes: 0

Aman
Aman

Reputation: 548

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...

Upvotes: 0

Related Questions