Java 佛教日历中的JSpinner日期编辑器
有没有办法将JSpinner.DateEditor与佛教日历一起使用?当我将我的区域设置更改为“th”、“th”并重新创建日历时,它们确实是佛教日历。但是,jspinner不会更新。以下是一些示例代码:Java 佛教日历中的JSpinner日期编辑器,java,calendar,jspinner,Java,Calendar,Jspinner,有没有办法将JSpinner.DateEditor与佛教日历一起使用?当我将我的区域设置更改为“th”、“th”并重新创建日历时,它们确实是佛教日历。但是,jspinner不会更新。以下是一些示例代码: Locale locale = new Locale("th", "TH"); Locale.setDefault(locale); // Reinitializing calendars with new locale, this is done correctly encodingCalen
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);
有什么想法吗?尝试设置微调器的区域设置:
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);
}
}
我已经尝试过更新我在示例代码中发布的区域设置。我尝试用新的javax.swing.SpinnerDateModel(expirationCalendar.getTime(),null,null,Calendar.MONTH)重新创建SpinnerDateModel,但没有成功。我相信您必须设置spinner的区域设置。我添加了一个SSCCE和屏幕截图。