Source Code : Creating an Hour JSpinner Component
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Creating an Hour JSpinner Component
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JFormattedTextField;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
import javax.swing.text.DateFormatter;
import javax.swing.text.DefaultFormatterFactory;
public class Main {
public static void main(String[] argv) throws Exception {
Calendar calendar = new GregorianCalendar();
calendar.set(Calendar.HOUR_OF_DAY, 13); // 1pm
SpinnerDateModel dateModel = new SpinnerDateModel(calendar.getTime(), null,
null, Calendar.HOUR_OF_DAY);
JSpinner spinner = new JSpinner(dateModel);
JFormattedTextField tf = ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField();
DefaultFormatterFactory factory = (DefaultFormatterFactory) tf.getFormatterFactory();
DateFormatter formatter = (DateFormatter) factory.getDefaultFormatter();
// Change the date format to only show the hours
formatter.setFormat(new SimpleDateFormat("hh:00 a"));
//formatter.setFormat(new SimpleDateFormat("HH:00 a"));
}
}
Thank with us