| Author |
JTable
|
Rangarajan Balasubramanian
Greenhorn
Joined: Jun 10, 2005
Posts: 9
|
|
How to pass Vectors to a JTable. When i am passing a vector i get a ClassCastException. How to go about it. // for creating table headers Vector column=new Vector(3); column.addElement("Policy No"); column.addElement("Policy Name"); column.addElement("Policy Type"); Vector fields=new Vector(10,2); ResultSet rs=stmt.executeQuery("select pno,ptype,pcode from customer"); while(rs.next()) { String pno=rs.getString(1); String ptype=rs.getString(2); String pcode=rs.getString(3); System.out.println(pno); fields.addElement(pno); fields.addElement(ptype); fields.addElement(pcode); } Vector rowData=new Vector(fields); DefaultTableModel dtm=new DefaultTableModel(); table=new JTable(dtm); // Exception occured dtm.setDataVector(rowData,column); jsp = new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); //Exception Occured java.lang.ClassCastException at javax.swing.table.DefaultTableModel.justifyRows(Unknown Source) at javax.swing.table.DefaultTableModel.setDataVector(Unknown Source) at com.classes.ui.CustomerDetails.viewCustPolicy(CustomerDetails.java:81 8) at com.classes.ui.CustomerDetails.actionPerformed(CustomerDetails.java:4 42) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknow n Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour ce) at java.awt.Component.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
|
 |
qunfeng wang
Ranch Hand
Joined: Jan 28, 2005
Posts: 407
|
|
It seems you have some problem in using JTable. Please come to here: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html for more details.
|
To be or not to be. It's a question.
|
 |
Palash Ray
Greenhorn
Joined: Mar 17, 2006
Posts: 3
|
|
You need to use a Vector of Vector. Vector cellsInRow1 = new Vector(); cellsInRow1.addElement("1"); cellsInRow1.addElement("2"); cellsInRow1.addElement("3"); cellsInRow1.addElement("4); Vector rows = new Vector(); rows.addElement(cellsInRow1); And then in the table model, pass rows as the argument.
|
 |
 |
|
|
subject: JTable
|
|
|