• Post Reply 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mi Chu
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tred by adding this code to my tablemodel class:



This doesnot help either
 
Rob Camick
Rancher
Posts: 3324
32
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mi Chu
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??

 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
- your model is incomplete

- notifiers betweens model and underlaing array doesn't works

- start with plain model without implements the seperate array
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mi Chu
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!

 
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic