佛教日历中的JSpinner日期编辑器

JSpinner Date Editor in Buddhist Calendar(佛教日历中的JSpinner日期编辑器)
本文介绍了佛教日历中的JSpinner日期编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

有没有办法将 JSpinner.DateEditor 与佛教日历一起使用?当我将语言环境更改为th"、TH"并重新创建我的日历时,它们确实是佛教日历.但是,JSpinners 没有更新.下面是一些示例代码:

Is there a way to use JSpinner.DateEditor with a Buddhist Calendar? When I change my locale to "th", "TH" and recreate my calendars they are indeed Buddhist Calendars. However, the JSpinners are not updated. Here is some sample code:

Locale locale = new Locale("th", "TH");
Locale.setDefault(locale);
// Reinitializing calendars with new locale, this is done correctly
encodingCalendar = Calendar.getInstance();
expirationCalendar = Calendar.getInstance();
// Modifying the spinners in another class to update them with the correct locale
// this is the part that's not doing what I'd expect.
editor.getExpirationDateSpinner().setLocale(locale);
editor.getExpirationDateSpinner().getEditor().setLocale(locale);

有什么想法吗?

推荐答案

尝试设置微调器的语言环境:

Try setting the spinner's locale:

import java.awt.EventQueue;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class JSpinnerTest extends JPanel {

    public static void main(String args[]) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                JFrame f = new JFrame("JSpinnerTest");
                f.add(new JSpinnerTest());
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.pack();
                f.setVisible(true);
            }
        });
    }

    public JSpinnerTest() {
        final JLabel label = new JLabel();
        final JSpinner spinner = new JSpinner();
        spinner.setLocale(new Locale("th", "TH"));
        Calendar calendar = Calendar.getInstance();
        Date initDate = calendar.getTime();
        calendar.add(Calendar.YEAR, -5);
        Date earliestDate = calendar.getTime();
        calendar.add(Calendar.YEAR, 10);
        Date latestDate = calendar.getTime();
        spinner.setModel(new SpinnerDateModel(
            initDate, earliestDate, latestDate, Calendar.MONTH));
        spinner.setEditor(new JSpinner.DateEditor(spinner, "MMM yyyy"));
        spinner.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                JSpinner s = (JSpinner) e.getSource();
                label.setText(s.getValue().toString());
            }
        });
        label.setText(initDate.toString());
        this.add(label);
        this.add(spinner);
    }
}

这篇关于佛教日历中的JSpinner日期编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Month is not printed from a date - Java DateFormat(月份不是从日期打印的 - Java DateFormat)
java get week of year for given a date(java获取给定日期的一年中的一周)
Get the number of days, weeks, and months, since Epoch in Java(获取自 Java 中的 Epoch 以来的天数、周数和月数)
Is there a good way to get the date of the coming Wednesday?(有什么好方法可以得到即将到来的星期三的日期吗?)
Calendar view for Android GingerBread and before (APIlt;11)(Android GingerBread 及之前的日历视图 (API11))
How to save and retrieve Date in SharedPreferences(如何在 SharedPreferences 中保存和检索日期)