1.日历的界面
2.导入datepick.jar包
http://115.159.110.11:9009/out/datepicker.jar
引用:
JAVA Swing日期选择控件datepicker的使用
https://blog.csdn.net/baidu_35085676/article/details/72903756
原
JAVA Swing日期选择控件datepicker的使用
使用方法
- 导入
在eclipse中,单击你的项目名,右键–>Build Path–>Add External Archives–>选择datepicker.jar - 使用
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
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 CCCC {
public static void main(String[] args) {
JFrame f = new JFrame("LoL");
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);
f.add(b);
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(f, "获取控件中的日期:" + datepick.getValue());
System.out.println(datepick.getValue());//这是一个java.util.Date对象
}
});
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(177, 24);
int[] hilightDays = { 1, 3, 5, 7 };
int[] disabledDays = { 4, 6, 5, 9 };
//构造方法(初始时间,时间显示格式,字体,控件大小)
datepick = new DatePicker(date, DefaultFormat, font, dimension);
datepick.setLocation(137, 83);//设置起始位置
/*
//也可用setBounds()直接设置大小与位置
datepick.setBounds(137, 83, 177, 24);
*/
// 设置一个月份中需要高亮显示的日子
datepick.setHightlightdays(hilightDays, Color.red);
// 设置一个月份中不需要的日子,呈灰色显示
datepick.setDisableddays(disabledDays);
// 设置国家
datepick.setLocale(Locale.CANADA);
// 设置时钟面板可见
datepick.setTimePanleVisible(true);
return datepick;
}
}
- 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
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 效果
原
JAVA Swing日期选择控件datepicker的使用
使用方法
- 导入
在eclipse中,单击你的项目名,右键–>Build Path–>Add External Archives–>选择datepicker.jar - 使用
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
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 CCCC {
public static void main(String[] args) {
JFrame f = new JFrame("LoL");
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);
f.add(b);
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(f, "获取控件中的日期:" + datepick.getValue());
System.out.println(datepick.getValue());//这是一个java.util.Date对象
}
});
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(177, 24);
int[] hilightDays = { 1, 3, 5, 7 };
int[] disabledDays = { 4, 6, 5, 9 };
//构造方法(初始时间,时间显示格式,字体,控件大小)
datepick = new DatePicker(date, DefaultFormat, font, dimension);
datepick.setLocation(137, 83);//设置起始位置
/*
//也可用setBounds()直接设置大小与位置
datepick.setBounds(137, 83, 177, 24);
*/
// 设置一个月份中需要高亮显示的日子
datepick.setHightlightdays(hilightDays, Color.red);
// 设置一个月份中不需要的日子,呈灰色显示
datepick.setDisableddays(disabledDays);
// 设置国家
datepick.setLocale(Locale.CANADA);
// 设置时钟面板可见
datepick.setTimePanleVisible(true);
return datepick;
}
}
- 效果