java:jdatechooser显示错误的月份

jq6vz3qz  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(433)

我在eclipse中使用超简单表单,并使用jcalendar1.4中的jdatechooser。我在jframe中添加组件,运行代码,日期选择器似乎是正确的,但是当我选择一个日期时,组件显示的是月份的名称,而不是30/11/2020


package a_vistas;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.toedter.calendar.JDateChooser;

public class Test extends JFrame {

    private JPanel contentPane;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Test frame = new Test();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public Test() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        JDateChooser dateChooser = new JDateChooser();
        dateChooser.setDateFormatString("dd/MM/yyyy");
        dateChooser.setBounds(71, 43, 259, 20);
        contentPane.add(dateChooser);
    }
}
xesrikrc

xesrikrc1#

你的例子对我很有用 JCalendar 1.4和Java1.8。我不确定它是否有用,但您可以在类路径中查找旧版本。

经测试:

import com.toedter.calendar.JDateChooser;
import java.awt.EventQueue;
import java.util.Date;
import java.util.Locale;
import javax.swing.JFrame;

public class Test extends JFrame {

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                Test frame = new Test();
                frame.setVisible(true);
            }
        });
    }

    public Test() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JDateChooser dateChooser = new JDateChooser(new Date());
        dateChooser.setLocale(new Locale("es"));
        dateChooser.setDateFormatString("dd/MM/yyyy");
        add(dateChooser);
        pack();
        setLocationRelativeTo(null);
    }
}

相关问题