jspinner 的 jtable 值未显示
问题是无法获取从 jtable 到 jspinner 显示的值。这是我的 jtablemouseclickedeven
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {
if(evt.getClickCount()==1){
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).toString());
}
}
jspinner 格式为 MM/dd/yyyy 所以 jtable 也是...
感谢任何可以再次帮助我的人...
这是我得到的错误:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: illegal value
at javax.swing.SpinnerDateModel.setValue(SpinnerDateModel.java:440)
at javax.swing.JSpinner.setValue(JSpinner.java:329)
at UsernamePasswordPackage.MainForm.jTable1MouseClicked(MainForm.java:930)
at UsernamePasswordPackage.MainForm.access$1600(MainForm.java:34)
at UsernamePasswordPackage.MainForm$17.mouseClicked(MainForm.java:337)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
at java.awt.Component.processMouseEvent(Component.java:6270)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6032)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
谢谢
problem is can't get the value displayed from jtable to jspinner. here is my jtablemouseclickedeven
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {
if(evt.getClickCount()==1){
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).toString());
}
}
jspinner is formatted as MM/dd/yyyy so the jtable also...
thanks to anyone who could help me again...
here is the error i get:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: illegal value
at javax.swing.SpinnerDateModel.setValue(SpinnerDateModel.java:440)
at javax.swing.JSpinner.setValue(JSpinner.java:329)
at UsernamePasswordPackage.MainForm.jTable1MouseClicked(MainForm.java:930)
at UsernamePasswordPackage.MainForm.access$1600(MainForm.java:34)
at UsernamePasswordPackage.MainForm$17.mouseClicked(MainForm.java:337)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
at java.awt.Component.processMouseEvent(Component.java:6270)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6032)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然这是另一个重复,但我会再试一次:您使用
SpinnerDateModel
并传递一个字符串作为值 (jTable1.getValueAt(jTable1.getSelectedRow(), 4).toString()< /code>) 而不是日期。在将字符串传递给微调器之前,将其转换为日期(或者您甚至可能已经获得了日期)。
编辑:我将此答案发布到原始问题,因此版主可能会删除此重复项。
Although this is another duplicate, I'll try again: 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.Edit: I posted this answer to the original question, so a moderator might delete this duplicate.