社区
Java SE
帖子详情
求 好看的 swing 时间控件 , 能支持 yyyy-MM-dd HH:mm:ss 的最好
billwindows
2008-02-28 11:26:32
我在 网上找到一个 ,但老板说不好看 ,郁闷ing !-_-
...全文
1404
17
打赏
收藏
求 好看的 swing 时间控件 , 能支持 yyyy-MM-dd HH:mm:ss 的最好
我在 网上找到一个 ,但老板说不好看 ,郁闷ing !-_-
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
17 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
luanwuqingyang
2010-08-24
打赏
举报
回复
真的很有用吗,也给我发一下吧!email:fengyu_001@126.com 谢谢!
xiedayun
2008-04-15
打赏
举报
回复
大侠,有时间请给我发个这样的时间控件,EMAIL:xiedayun2008@163.com.
谢谢!
O2AtomLife
2008-04-15
打赏
举报
回复
一样做了,干嘛时间不做好,输错都不能提交
tangqingguang111
2008-03-25
打赏
举报
回复
上面的兄弟,我现在也正需要一个这样的组件。可以给我发一个齐全的吗?Email:tqingguang6688@126.com
billwindows
2008-03-03
打赏
举报
回复
问题解决~oo~
SINODATA_QJF
2008-03-01
打赏
举报
回复
此段程序已经做了整理,打成了JAR包,上传到资源库中,请自行下载
http://d.download.csdn.net/down/365468/SINODATA_QJF
billwindows
2008-02-29
打赏
举报
回复
神那,我快被你打败了~ NTriangle.java 这个类是 怎么写的哇 ? 可以把代码发到邮箱里么? 我邮箱是lixin211314@163.com 小弟再次感激不尽!
billwindows
2008-02-29
打赏
举报
回复
对了 ,哥们 告诉你个事 ,粘java 或者其他 程序可以 用这个csdn 上的工具,就发帖子的地方, 你点 带 # 图标的 按钮,就可以插入java 代码,在 那对标签里写东西就可以完整的把java 程序 拷贝过去了.就一次就ok 嘎嘎 例如:
System.out.pringtln("挖哈哈!")
billwindows
2008-02-29
打赏
举报
回复
你写的那些 N 打头的 一定全是 把 api 的类包了 一层,哈哈 ~oo~
billwindows
2008-02-29
打赏
举报
回复
十分感谢这个世界上还有你这样好的human,祝福你新的一年袄袄快乐 ~oo~
billwindows
2008-02-28
打赏
举报
回复
那先谢谢啦 ~oo~
SINODATA_QJF
2008-02-28
打赏
举报
回复
有是有,晚上提供给你啦
SINODATA_QJF
2008-02-28
打赏
举报
回复
晕,程序教长,传了4次
不过,此程序中,可能还引用到了别的类,不过那都是次要的
如:StringHandle类,基本是自己进行重新弄下就可以了
对了,N字头的类,把它改为J就行了
SINODATA_QJF
2008-02-28
打赏
举报
回复
private void fillInDayTabel(Calendar calendar) {
if( hField == NDateChooser.HAS_YMDF || hField == NDateChooser.HAS_YMDTF ) {
int totalDays,dayOfWeek,rowNumber,remainer,totalRowCount,counter =0;
rowData = new Vector(5,5);
totalDays = calendar.getActualMaximum(calendar.DAY_OF_MONTH);
ExtendCalendar tempCalendar = new ExtendCalendar(calendar.get(calendar.YEAR),calendar.get(calendar.MONTH),1);
dayOfWeek = tempCalendar.get(tempCalendar.DAY_OF_WEEK);
tempCalendar = null;
remainer = totalDays + dayOfWeek - 15;
for( rowNumber = 1; remainer >0; rowNumber++) {
remainer -= 7;
}
rowNumber++;
totalRowCount = dateChooserTableModel.getRowCount();
for( int rowCount = 0; rowCount < totalRowCount; rowCount ++) {
dateChooserTableModel.removeRow(0);
}
for( int i = 0; (counter < totalDays) && ( i < rowNumber ); i++ ) {
rowData.addElement(new Vector(5,5));
Vector v = (Vector) rowData.elementAt(i);
if( i == 0 ) {
for( int m = 1; m < dayOfWeek; m++ ) {
v.addElement("");
}
}
for( int j = ((i==0)? dayOfWeek : 1); (j <=7) && (counter < totalDays); j++) {
v.addElement(new Integer(++counter));
if( counter == totalDays ) {
for( ; j <= 7; j++ ) {
v.addElement("");
}
}
}
dateChooserTableModel.addRow(v);
}
dateChooserTable.repaint();
int row = currentSelectedCalendar.get(Calendar.WEEK_OF_MONTH) - 1;
int column = currentSelectedCalendar.get(Calendar.DAY_OF_WEEK) - 1;
dateChooserTable.setRowSelectionInterval(row,row);
dateChooserTable.setColumnSelectionInterval(column,column);
}
}
}
class GoingTimeThread extends Thread {
private static int SLEEPTIME = 1000;
private NTextField itf;
private String strValue = "", oldStrValue = "";
private boolean iNeedToStop = false; //是否需要停止线程, true运行线程 false停止线程
private int currentHour,currentMinute,currentSecond;
public GoingTimeThread(NTextField txtField) {
super();
this.itf = txtField;
}
public void run() {
while( ! iNeedToStop ) {
try {
Thread.sleep(SLEEPTIME);
} catch (InterruptedException e) {}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
setTimeTextField(itf);
}
});
}
}
public void setTimeTextField(NTextField ajtf) {
String sHour,sMinute,sSecond;
Calendar timeCalendar = new ExtendCalendar(TimeZone.getDefault(),Locale.getDefault());
if( timeCalendar.get(Calendar.AM_PM) == Calendar.PM ) { //is pm
currentHour = timeCalendar.get(Calendar.HOUR) + 12;
sHour = (new Integer(currentHour)).toString();
} else {
currentHour = timeCalendar.get(timeCalendar.HOUR);
sHour = (new Integer(currentHour)).toString();
}
currentMinute = timeCalendar.get(timeCalendar.MINUTE);
sMinute = (new Integer(currentMinute)).toString();
currentSecond = timeCalendar.get(timeCalendar.SECOND);
sSecond = (new Integer(currentSecond)).toString();
sHour = StringHandle.fixLengthRight(sHour,'0',2);
sMinute = StringHandle.fixLengthRight(sMinute,'0',2);
sSecond = StringHandle.fixLengthRight(sSecond,'0',2);
oldStrValue = strValue.toString();
strValue = sHour + ":" + sMinute + ":" + sSecond;
ajtf.setText(strValue);
ajtf.repaint();
}
public String getTextFieldStr() {
return oldStrValue;
}
public void setNeedToStop(boolean blNeedStop) {
this.iNeedToStop = blNeedStop;
}
public boolean getNeedToStop() {
return this.iNeedToStop;
}
}
class ExtendCalendar extends GregorianCalendar {
public ExtendCalendar() {
this.complete();
}
public ExtendCalendar(TimeZone timeZone,Locale locale) {
super(timeZone,locale);
this.complete();
}
public ExtendCalendar(int year,int month,int day) {
super(year,month,day);
this.complete();
}
}
SINODATA_QJF
2008-02-28
打赏
举报
回复
private void monthComboBox_actionPerformed(ActionEvent e) {
if( monthComboBox.getSelectedIndex() < 0 ) return;
currentSelectedCalendar.set(Calendar.MONTH,monthComboBox.getSelectedIndex());
adjustDay(currentSelectedCalendar,monthComboBox.getSelectedIndex());
fillInDayTabel(currentSelectedCalendar);
}
private void adjustDay(Calendar cal,int selMonth) {
int day = cal.get(cal.DATE);
int month = cal.get(cal.MONTH);
if(month > selMonth) {
cal.set(cal.get(cal.YEAR),selMonth,day);
}
}
//判断是确认还是取消
public boolean isApplied() {
return (clickBtn == CLICK_CONFIRM);
}
public Calendar getCalendar() {
return this.currentSelectedCalendar;
}
public void setCalendar(Calendar aCalendar) {
currentSelectedCalendar = (Calendar)aCalendar.clone();
goingTimeThread.setNeedToStop(true);
try {
goingTimeThread.suspend();
} catch ( Exception ex ) {
System.out.println("goingTimeThread.suspend");
}
if( !currentSelectedCalendar.equals(rightNow) ) {
yearTextField.setText(new Integer(currentSelectedCalendar.get(Calendar.YEAR)).toString());
monthComboBox.setSelectedIndex(currentSelectedCalendar.get(Calendar.MONTH));
NDateDocument dateDocument = new NDateDocument(timeTextField);
timeTextField.setDocument(dateDocument);
fillTimeToTimeTextField(dateDocument,timeToStr(currentSelectedCalendar));
}
}
private void fillTimeToTimeTextField(NDateDocument doc,String sourceStr) {
try {
doc.insertString(0,sourceStr.substring(0,2),null);
doc.insertString(3,sourceStr.substring(3,5),null);
doc.insertString(6,sourceStr.substring(6,8),null);
} catch (Exception ex) {
System.out.println("fillTimeToTimeTextField error");
}
}
private String timeToStr(Calendar calendar) {
return "12:10";
}
private String currentSelectedTime = "";
private boolean validateTime() {
try {
if( goingTimeThread.isAlive() ) {
goingTimeThread.setNeedToStop(true);
}
currentSelectedTime = timeTextField.getText(); //不知道timeTextField对不对。请确认
int hour,minute,second;
hour = getIntValue(currentSelectedTime,0);
minute = getIntValue(currentSelectedTime,3);
second = getIntValue(currentSelectedTime,6);
if( hour >23 || minute > 59 || second > 59 ) {
//JOptionPane.showMessageDialog(""); //报告错误
System.out.println(" hour >23 || minute > 59 || second > 59");
return false;
} else {
currentSelectedCalendar = new GregorianCalendar(currentSelectedCalendar.get(Calendar.YEAR),currentSelectedCalendar.get(Calendar.MONTH),currentSelectedCalendar.get(Calendar.DATE),hour,minute,second);
return true;
}
} catch ( NumberFormatException ex) {
//JOptionPane.showMessageDialog(""); //报告错误
System.out.println("NumberFormatException");
return false;
}
}
public static int ILLEGALTIME = 1000;
private int getIntValue(String sourceStr,int off) {
String subStr ="";
Integer returnIntegerValue;
try {
if( off == 6 ) {
subStr = sourceStr.substring(off);
} else {
subStr = sourceStr.substring(off,off+2);
}
} catch (IndexOutOfBoundsException ex) {
System.out.println("IndexOutOfBoundsException error!");
}
try {
returnIntegerValue = new Integer(subStr);
} catch (NumberFormatException ex) {
returnIntegerValue = new Integer(ILLEGALTIME);
}
return returnIntegerValue.intValue();
}
private int hField = NDateChooser.HAS_YMDF;
private GoingTimeThread goingTimeThread = new GoingTimeThread(timeTextField);
private void initData() {
for(int i = 0; i < monthItems.length; i++) {
monthComboBox.addItem(monthItems[i]);
}
monthComboBox.setSelectedIndex(rightNow.get(rightNow.MONTH));
yearTextField.setEditable(false);
yearTextField.setText(new Integer(rightNow.get(rightNow.YEAR)).toString());
dateChooserTable.setCellSelectionEnabled(true);
dateChooserTable.setColumnSelectionAllowed(true);
dateChooserTable.setRowSelectionAllowed(true);
dateChooserTable.setSelectionBackground(Color.lightGray);
dateChooserTable.setSelectionForeground(Color.RED);
dateChooserTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
dateChooserTable.setRowHeight(SwingConfig.TableRowHeight);
if( hField == NDateChooser.HAS_TF || hField == NDateChooser.HAS_YF || hField == NDateChooser.HAS_YMF ) {
mainPanel.setPreferredSize(new Dimension(300,125));
} else {
mainPanel.setPreferredSize(new Dimension(400,280));
}
if( hField == NDateChooser.HAS_YMDTF || hField == NDateChooser.HAS_TF ) {
goingTimeThread.setTimeTextField(timeTextField);
}
switch( hField ) {
case NDateChooser.HAS_YF:
monthComboBox.setVisible(false);
case NDateChooser.HAS_YMF:
chooserDayScrollPane.setVisible(false);
case NDateChooser.HAS_YMDF:
timeTextField.setVisible(false);
fillInDayTabel(rightNow);
break;
case NDateChooser.HAS_TF:
yearTextField.setVisible(false);
monthComboBox.setVisible(false);
chooserDayScrollPane.setVisible(false);
upYearButton.setVisible(false);
downYearButton.setVisible(false);
case NDateChooser.HAS_YMDTF:
fillInDayTabel(rightNow);
goingTimeThread.start();
break;
default: //请后面修正这里的代码
System.out.println("error");
fillInDayTabel(rightNow);
}
}
private Vector rowData;
SINODATA_QJF
2008-02-28
打赏
举报
回复
cancleButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cancleButton_actionPerformed(e);
}
});
confirmButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
confirmButton_actionPerformed(e);
}
});
dateChooserTable.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
dateChooserTable_cliecked(e);
}
});
timeTextField.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
timeTextField_focusGained(e);
}
});
}
private int getSelectYear(int iord) {
Integer integer;
String text = yearTextField.getText();
try {
integer = new Integer(text);
} catch (NumberFormatException ex) {
integer = new Integer(iord);
}
int tpi = integer.intValue();
if(iord == INDICATOR_OP_UP) {
integer = new Integer(++tpi);
if( tpi > 9999 ) {
integer = new Integer(9999);
}
yearTextField.setText(integer.toString());
return integer.intValue();
} else {
integer = new Integer(--tpi);
if( tpi < 1 ) {
integer = new Integer(1);
}
yearTextField.setText(integer.toString());
return integer.intValue();
}
}
private void timeTextField_focusGained(FocusEvent e) {
if( goingTimeThread!= null && goingTimeThread.getNeedToStop() == false ) {
goingTimeThread.setNeedToStop(true);
}
}
public static int INDICATOR_OP_NONE = 0;
public static int INDICATOR_OP_UP = 1;
public static int INDICATOR_OP_DOWN = 2;
private void upYearButton_actionPerformed(ActionEvent e) {
int year = getSelectYear(INDICATOR_OP_UP);
currentSelectedCalendar.set(Calendar.YEAR,year);
fillInDayTabel(currentSelectedCalendar);
}
private void downYearButton_actionPerformed(ActionEvent e) {
int year = getSelectYear(INDICATOR_OP_DOWN);
currentSelectedCalendar.set(Calendar.YEAR,year);
fillInDayTabel(currentSelectedCalendar);
}
public static int CLICK_CONFIRM = 1;
public static int CLICK_CANCLE = 2;
private int clickBtn = CLICK_CANCLE;
private void cancleButton_actionPerformed(ActionEvent e) {
if( goingTimeThread.isAlive() ) {
goingTimeThread.setNeedToStop(true);
}
clickBtn = CLICK_CANCLE;
this.setVisible(false);
}
private void confirmButton_actionPerformed(ActionEvent e) {
switch( hField ) {
case NDateChooser.HAS_TF:
if( validateTime()) {
clickBtn = CLICK_CONFIRM;
this.setVisible(false);
}
break;
case NDateChooser.HAS_YMDTF:
if( !validateTime() ) {
break;
}
case NDateChooser.HAS_YMDF:
if( !validateTime() ) {
break;
}
case NDateChooser.HAS_YMF:
case NDateChooser.HAS_YF:
clickBtn = CLICK_CONFIRM;
this.setVisible(false);
break;
default:
}
}
private void dateChooserTable_cliecked(MouseEvent me) {
if( dateChooserTable.getSelectedColumn() != -1 ) {
String s = dateChooserTable.getValueAt(dateChooserTable.getSelectedRow(),dateChooserTable.getSelectedColumn()).toString();
try {
Integer integer = new Integer(s);
currentSelectedCalendar.set(Calendar.DATE,integer.intValue());
} catch (NumberFormatException ex) {}
if( me.getClickCount() == 2 && me.getModifiers() == MouseEvent.BUTTON1_MASK && s != null && !s.equals("")) {
confirmButton_actionPerformed(null);
}
}
}
SINODATA_QJF
2008-02-28
打赏
举报
回复
程序稍长,为三次贴出,
import javax.swing.*;
import javax.swing.border.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import catic.library.swing.*;
import catic.library.swing.tree.*;
import catic.library.swing.table.*;
import catic.library.config.SwingConfig;
import catic.library.lang.StringHandle;
public class NDateChooserDlg extends NDialog {
private NPanel mainPanel = new NPanel();
private NPanel subPanel = new NPanel();
private NTextField yearTextField = new NTextField();
private JButton upYearButton = new JButton(new NTriangle(Color.black,NTriangle.UP) );
private JButton downYearButton = new JButton(new NTriangle(Color.black,NTriangle.DOWN) );
private NComboBox monthComboBox = new NComboBox();
private NTextField timeTextField = new NTextField();
private NScrollPane chooserDayScrollPane = new NScrollPane();
private ExtendCalendar rightNow = new ExtendCalendar(TimeZone.getDefault(),Locale.getDefault());
private Calendar currentSelectedCalendar = (ExtendCalendar)rightNow.clone();
private String[] dateChooserColums = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
private NTableModel dateChooserTableModel = new NTableModel(dateChooserColums);
private NTable dateChooserTable = new NTable(dateChooserTableModel);
private String[] monthItems = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
private NPanel buttonPanel = new NPanel();
private NButton confirmButton = new NButton("确定");
private NButton cancleButton = new NButton("取消");
public NDateChooserDlg(JFrame frame,boolean model) {
this(frame,null,true,NDateChooser.HAS_YMDTF);
}
public NDateChooserDlg(JFrame frame,String title,boolean model) {
this(frame,title,true,NDateChooser.HAS_YMDTF);
}
public NDateChooserDlg(JFrame frame,String title,boolean model,int hasField) {
super(frame,title,model);
this.hField = hasField;
initData();
try {
initComponent();
pack();
} catch (Exception e) {}
}
private void initComponent() {
TitledBorder titleBorder = new TitledBorder(BorderFactory.createLineBorder(Color.gray,1),"日期/时间属性");
titleBorder.setTitleFont(NComponentFeature.getFont(NComponentFeature.FONT_DEFAULT));
subPanel.setBorder(BorderFactory.createCompoundBorder(titleBorder,BorderFactory.createEmptyBorder(5,5,5,5)));
subPanel.setLayout(new GridBagLayout());
yearTextField.setPreferredSize(new Dimension(60,20));
yearTextField.setMinimumSize(new Dimension(60,20));
upYearButton.setPreferredSize(new Dimension(20,10));
upYearButton.setMinimumSize(new Dimension(20,10));
downYearButton.setPreferredSize(new Dimension(20,10));
downYearButton.setMinimumSize(new Dimension(20,10));
subPanel.add(yearTextField,new GridBagConstraints(0,0,1,2,0.0,0.0,GridBagConstraints.NORTHWEST,GridBagConstraints.HORIZONTAL,new Insets(0,0,0,0),50,0));
subPanel.add(upYearButton,new GridBagConstraints(1,0,1,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(0,0,0,0),0,0));
subPanel.add(downYearButton,new GridBagConstraints(1,1,1,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(0,0,0,0),0,0));
subPanel.add(monthComboBox,new GridBagConstraints(2,0,1,2,0.0,0.0,GridBagConstraints.NORTHWEST,GridBagConstraints.HORIZONTAL,new Insets(0,10,0,0),40,-2));
subPanel.add(timeTextField,new GridBagConstraints(3,0,1,2,1.0,0.0,GridBagConstraints.NORTHWEST,GridBagConstraints.HORIZONTAL,new Insets(0,10,0,0),0,0));
subPanel.add(chooserDayScrollPane,new GridBagConstraints(0,2,4,1,1.0,1.0,GridBagConstraints.WEST,GridBagConstraints.BOTH,new Insets(10,0,0,0),0,0));
dateChooserTableModel.setCellEditTable(false);
chooserDayScrollPane.getViewport().add(dateChooserTable,null);
buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
buttonPanel.add(confirmButton);
buttonPanel.add(cancleButton);
mainPanel.setLayout(new GridBagLayout());
mainPanel.add(subPanel,new GridBagConstraints(0,0,1,1,1.0,1.0,GridBagConstraints.WEST,GridBagConstraints.BOTH,new Insets(0,0,0,0),0,0));
mainPanel.add(buttonPanel,new GridBagConstraints(0,1,1,1,1.0,0.0,GridBagConstraints.WEST,GridBagConstraints.BOTH,new Insets(10,0,0,0),0,0));
mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
this.getContentPane().add(mainPanel,BorderLayout.CENTER);
monthComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
monthComboBox_actionPerformed(e);
}
});
downYearButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
downYearButton_actionPerformed(e);
}
});
upYearButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
upYearButton_actionPerformed(e);
}
});
java
swing
时间
控件
_
Swing
实现日期选择器DatePicker(带时分秒选择功能)
本文介绍了如何使用Java
Swing
创建一个日期选择器组件DateSelector,该组件不仅可以选择日期,还
支持
选择时、分、秒。通过自定义JSpinner和JButton实现日期和
时间
的选择,展示了一个包含年、月、日、小时、分钟和秒的完整选择器,并提供了设置默认日期和获取选定日期的功能。
时间
组件
本文介绍了一种基于Java
Swing
的日期选择器实现方案,包括单
时间
组件和双
时间
组件。单
时间
组件提供基本的
时间
选择功能,而双
时间
组件则用于选择起始
时间
和结束
时间
,并
支持
多种日期格式。
格式化输入日期
时间
控件
JieFormatte
dD
ateBox
介绍了一种自定义的格式化日期
时间
控件
JieFormatte
dD
ateBox,
支持
多种日期
时间
格式,并能应用于JSpinner组件中,实现日期
时间
的便捷输入与调整。
Jsp网络拓扑图--用java实现网络拓扑图
本文介绍如何使用Java和多比图形
控件
实现基于Web的网络拓扑图动态绘制,融合了Web功能和网管技术,使网管人员能直观监控网络设备状态、流量及拓扑结构,及时发现故障,保障用户网络学习与工作。
C#为何成为2002年开发者的技术破局点
本文剖析C#在2002年成为开发者破局关键的技术动因:针对当时硬件受限、GUI开发断层、MFC陡峭学习曲线及面向对象落地难等痛点,C#凭借语法级资源管理(using)、.NET Framework对Win32 API的封装抽象、Visual Studio .NET的智能感知与重构能力,显著降低学习成本与工程门槛。其托管运行时、程序集机制和委托原语设计,为现代开发范式奠定基础。
Java SE
62,622
社区成员
307,257
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章