Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

exception while creating JTables

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
hi,
I am getting the following exception with my program.please chek this once.
Exception in thread "main" java.lang.ClassCastException
at javax.swing.table.DefaultTableModel.justifyRows DefaultTableModel.jav
a:238)
at javax.swing.table.DefaultTableModel.setDataVector(DefaultTableModel.j
ava:194)
at javax.swing.table.DefaultTableModel.<init>(DefaultTableModel.java:131
)
at guidemo.<init>(guidemo.java:37)
at guidemo.main(guidemo.java:60)
----------------------------------------------------------------
i am tried to create a table with vectors.my code is as follows
code:-
-----
class guidemo extends JFrame{
private JTable data_tab;
private JLabel ptitle;
private Container c;
private Vector vdata;
private Vector vcolname;

public guidemo(){
super("EST Project Demo");
DefaultTableModel dtm;

c=getContentPane();
c.setLayout(null);
c.setSize(300,200);//intialising the contentpane



ptitle=new JLabel("EST project Details");

ptitle.setBounds(60,30,150,40);

c.add(ptitle);
setTableData();//intialising the vectors with some data

dtm=new DefaultTableModel(vdata,vcolname);
data_tab=new JTable(dtm);//setting table model
//data_tab.setPreferredScrollableViewportSize(new Dimension(500, 100));
c.add(data_tab);

WindowListener wndCloser = new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
};

addWindowListener(wndCloser);
setVisible(true);

}

public static void main(String[] args)
{
System.out.println("Hello World!");
setDefaultLookAndFeelDecorated(true);
new guidemo();
}

public void setTableData(){//intialise vectors with some data
vdata=new Vector();
vcolname=new Vector();
vdata.removeAllElements();
vdata.addElement(new dat("Eliuh",90,900,"uy89"));
vdata.addElement(new dat("Eryuh",920,900,"uy89"));
vdata.addElement(new dat("Elddh",940,900,"uy89"));
vdata.addElement(new dat("Elideu",90,900,"uy89"));
vdata.addElement(new dat("Elwciuh",760,900,"uy89"));
vdata.addElement(new dat("Elhhiuh",90,900,"uy89"));
vdata.addElement(new dat("Elicuh",100,900,"uy89"));
vdata.addElement(new dat("Eliuech",90,900,"uy89"));
vcolname.addElement(new cname("NAME","QStart","Qend","PID"));
}

}

class dat{
String name,gid;
int val,val2;
public dat(String n,int v,int v1,String g){
name=n;
val=v;
val2=v1;
gid=g;

}
}
class cname{
String s1,s2,s3,s4;
cname(String q, String w, String t, String y){
s1=q;
s2=w;
s3=t;
s4=y;
}
}
----------------------------------------------------------
I am not able to understand why i am getting that exception.if any body have solution for my problem it will be greatly helpful for me.
thanks,
karan
 
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Closing since you already asked this in the Swing forum. Please do not cross-post the same question in multiple forums.
bear
JDBC Forum Bartender
[ March 19, 2004: Message edited by: Bear Bibeault ]
    Bookmark Topic Watch Topic
  • New Topic