-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatePickerTest.java
63 lines (59 loc) · 1.86 KB
/
DatePickerTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package java_GUI;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import java.util.Locale;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import com.eltima.components.ui.DatePicker;
public class DatePickerTest {
public static void main(String[] args) {
JFrame f = new JFrame("日期获取");
f.setSize(400, 300);
f.setLocation(200, 200);
f.setLayout(null);
final DatePicker datepick;
datepick = getDatePicker();
f.add(datepick);
JButton b = new JButton("获取时间");
b.setBounds(137, 183, 100, 30);//position and size
f.add(b);
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(f, "获取控件中的日期:" + datepick.getValue());
System.out.println(datepick.getValue());
}
});
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
private static DatePicker getDatePicker() {
final DatePicker datepick;
// 格式
String DefaultFormat = "yyyy-MM-dd HH:mm:ss";
// 当前时间
Date date = new Date();
// 字体
Font font = new Font("Times New Roman", Font.BOLD, 14);
Dimension dimension = new Dimension(300, 30);
int[] hilightDays = { 1, 3, 5, 7 };
int[] disabledDays = { 4, 6, 5, 9 };
datepick = new DatePicker(date, DefaultFormat, font, dimension);
datepick.setLocation(137, 83);
datepick.setBounds(130, 85, 180, 25);
// 设置一个月份中需要高亮显示的日子
datepick.setHightlightdays(hilightDays, Color.red);
// 设置一个月份中不需要的日子,呈灰色显示
datepick.setDisableddays(disabledDays);
// 设置国家
datepick.setLocale(Locale.CHINA);
// 设置时钟面板可见
datepick.setTimePanleVisible(true);
return datepick;
}
}