aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes “AWT-EventQueue-0” java.lang.ClassCastException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "“AWT-EventQueue-0” java.lang.ClassCastException" Watch "“AWT-EventQueue-0” java.lang.ClassCastException" New topic
Author

“AWT-EventQueue-0” java.lang.ClassCastException

Mithun Chennuru
Greenhorn

Joined: Dec 17, 2013
Posts: 13
My main objective is to add checkboxes to a column in the jtable. But, when I am trying to return the Boolean value for that cell, it is throwing { Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: com.ciber.ecc.ui.results.CellInfo incompatible with java.lang.Boolean}

My classes: DocumentTable.java



CellInfo.java




DocTableModel.java


The error is thrown at this line:

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2215
    
    7
JTable already supports a default renderer for check boxes. If you want a check box in one column then you add a Boolean variable to the TableModel, NOT a CellInfo object.

Read the section from the Swing tutorial on How to Use Tables for a working example that shows how to add Boolean data to the TableModel.
Mithun Chennuru
Greenhorn

Joined: Dec 17, 2013
Posts: 13
I tred by adding this code to my tablemodel class:



This doesnot help either
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2215
    
    7
Did you add a Boolean value to the TableModel? Post your SSCCE that shows where you add Boolean data. You can't add a CellInfo to column 0, if you want it to contain Boolean data.
Mithun Chennuru
Greenhorn

Joined: Dec 17, 2013
Posts: 13
Rob, here is what I did. This however gives checkbox only after I click and after each click its gone again. Should I also call a setValueAt() method, to add the Boolean data??

m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 156
- your model is incomplete

- notifiers betweens model and underlaing array doesn't works

- start with plain model without implements the seperate array
Sam Gooding
Ranch Hand

Joined: Dec 06, 2013
Posts: 35
ON the one had you (appear to be , without a SCCEE it's impossible to tell for sure) you appear to be setting the cell renderer to a JCheckBox and on the other you're declaring the cell type to be your own custom CellInfo type:




You seem to have built a substitute for the Boolean as your table data type. THe reason it's throwing is because it's not a Boolean type at the cell, it's a CellInfo-type thing.
Mithun Chennuru
Greenhorn

Joined: Dec 17, 2013
Posts: 13
Sam,
what SSCCE do you want from me? I posted the code that I have. I am unable to understand when you say SSCCE. Also, I am trying to write a setValueAt() method as follows:



but, getDataVector() is undefined for AbstractTableModel. How do i work around it? And as you said, how do I add Boolean value to my CellInfo object?/ Please help.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2215
    
    7
I am unable to understand when you say SSCCE.


Did you follow the link?

how do I add Boolean value to my CellInfo object?


You don't. You add the Boolean value to the TableModel. Every cell should contain its own Object.

Please help.


You've been given help. Did you read the Swing tutorial?. Did you see how the data is added to the TableModel.? What part of the tutorial do you not understand?
Sam Gooding
Ranch Hand

Joined: Dec 06, 2013
Posts: 35
Mithun Chennuru wrote:Sam,
what SSCCE do you want from me? I posted the code that I have. I am unable to understand when you say SSCCE. Also, I am trying to write a setValueAt() method as follows:



but, getDataVector() is undefined for AbstractTableModel. How do i work around it? And as you said, how do I add Boolean value to my CellInfo object?/ Please help.


OK first an SCCE is a self-contained compilable (it works!) example. You should post such a thing so that people can copy and paste it into their own editors and RUN it. This helps people debug your code and find the problem. It should NOT be big- specifically, it should not be *the code you are actually working on* in most cases since that's usually BIG and people's eyes just glaze over . What you want to do is try to distill the problem you're having into an SCCEE. That means writing a small program for no other purpose than 1) demonstrating the problem and 2) requesting help. It is (can be) some work, but people want you to do it. It's a norm.

Second , If you create your TableModel so that it is composed of Boolean type things, the JTable will, without further work required on your part display the table data as checkboxes like you're trying to do.

The TableModel is abstract but you can use DefaultTableModel which is not abstract and will accept Boolean type things as elements and give you a lot of what you're looking for. Definitely read the Swing tutorial on Oracle's site and reply back when you have a specific question. The smaller and more specific the question, the faster you'll get answers to your questions. Ask small specific questions , as many as you want. That's the best way to make progress against your problems..looking forward to working with you!

HTH!

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: “AWT-EventQueue-0” java.lang.ClassCastException