jspinner的jtable值未显示

时间:2011-03-22 07:36:14

标签: java netbeans 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)

感谢

1 个答案:

答案 0 :(得分:1)

虽然这是另一个重复,但我会再试一次:您使用SpinnerDateModel并传递一个字符串作为值(jTable1.getValueAt(jTable1.getSelectedRow(), 4).toString())而不是日期。在将字符串传递给微调器之前,将字符串转换为日期(或者您甚至可能已经有了日期)。

编辑:我将此答案发布到原始问题,因此主持人可能会删除此副本。