zoukankan      html  css  js  c++  java
  • e787. 用JSpinner实现小时选择

      // Create a calendar object and initialize to a particular hour if desired
        Calendar calendar = new GregorianCalendar();
        calendar.set(Calendar.HOUR_OF_DAY, 13); // 1pm
        
        // Create a date spinner that controls the hours
        SpinnerDateModel dateModel = new SpinnerDateModel(
            calendar.getTime(), null, null, Calendar.HOUR_OF_DAY);
        JSpinner spinner = new JSpinner(dateModel);
        
        // Get the date formatter
        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"));
        
        // Or use 24 hour mode
        formatter.setFormat(new SimpleDateFormat("HH:00 a"));
    
    Related Examples
  • 相关阅读:
    344.反正字符串
    125.验证回文串
    167.两数之和 II
    278.第一个错误的版本
    缓冲流
    Windows10剪贴板不能用
    chapter_21【字节流、字符流】
    属性集
    IO异常的处理
    字符流
  • 原文地址:https://www.cnblogs.com/borter/p/9596258.html
Copyright © 2011-2022 走看看