JTable日期值到jspinner [英] JTable date value to jspinner

查看:49
本文介绍了JTable日期值到jspinner的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经显示了一个格式为MM/dd/yyyy的日期值,并且我希望它在jtablemouseclickedevent上显示给jsinner.我该怎么办?我用此代码尝试过,但出现错误:

i have displayed a date value formatted MM/dd/yyyy and i want it to display to jsinner on jtablemouseclickedevent. how would i do that? i tried it with this code but i get an error:

我的jtable有5列

my jtable has 5 columns

ID = int type
Username = String type
Password = String type
Website = String type
Date Encoded = date/time type (MM/dd/yyyy)

这是我的代码:

jLabel5.setText(jTable1.getValueAt(jTable1.getSelectedRow(), 0).toString());
jTextField4.setText(jTable1.getValueAt(jTable1.getSelectedRow(), 1).toString());
jTextField5.setText(jTable1.getValueAt(jTable1.getSelectedRow(), 2).toString());
jTextField6.setText(jTable1.getValueAt(jTable1.getSelectedRow(), 3).toString());
**jSpinner1.setValue(jTable1.getValueAt(jTable1.getSelectedRow(), 4));**

任何帮助将不胜感激:) :):)

any help would be greatly appreciated :) :) :)

推荐答案

您使用 SpinnerDateModel 并传递一个字符串作为值( jTable1.getValueAt(jTable1.getSelectedRow(),4).toString())而不是日期.在将字符串传递给微调框之前,将其转换为日期(或者也许您已经有一个日期).

You use SpinnerDateModel and pass a String as the value (jTable1.getValueAt(jTable1.getSelectedRow(), 4).toString()) instead of a date. Convert the string to a date (or maybe you even got a date already) before passing it to the spinner.

这篇关于JTable日期值到jspinner的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆