Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

cell model and table display  RSS feed

 
Sayuri Coppinger
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a table that contains cells with different data types (text, double, integer, formatted double etc). The user can input values into these cells, and I need to come up with a way to determine if the input is correct. With textfields, I can customize the document, so it would only allow numbers or alpha values when the user tries to enter them, but how do I deal with this in a table. I know I need to create a cell model for each type since these types could be in any column/row. Is there another way to handle this problem, and can the cell model do something similar to the insertString method in the document object?
Also, some cells need to be created but the user does not want to see them since they are readonly. Aside from changing the background color, is there another to make these cells hidden?
I would really appreciate any ideas/input on this!
Thanks
 
Nathanael Ulrick
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I read you correctly, your table will not be able to guarantee that all fields under a single column will be of the same type. This complicates things.
What you'd need to do is create a custom CellEditor for your JTable. The CellEditor's job is to return a Component for the specified column and row in the table. This Component is what is used to edit the value stored in the cell.
This Component could be a JTextField or whatever you want, so yes, it would support insertString() if it were the correct Component.
There is a DefaultCellEditor in javax.swing, so you may not have to implement the full interface.

It's the same for viewing cells: a JTable has a CellRenderer. I don't understand what you're trying to do with cell hiding, but I assume you're just trying to make them look like solid blocks or something. (If you're trying to hide the entire column it would be easier.) You can make cells look like anything you want.
Originally posted by Sayuri Coppinger:
I am creating a table that contains cells with different data types (text, double, integer, formatted double etc). The user can input values into these cells, and I need to come up with a way to determine if the input is correct. With textfields, I can customize the document, so it would only allow numbers or alpha values when the user tries to enter them, but how do I deal with this in a table. I know I need to create a cell model for each type since these types could be in any column/row. Is there another way to handle this problem, and can the cell model do something similar to the insertString method in the document object?
Also, some cells need to be created but the user does not want to see them since they are readonly. Aside from changing the background color, is there another to make these cells hidden?
I would really appreciate any ideas/input on this!
Thanks

 
Sayuri Coppinger
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your input. I already have custom textfields with the appropriate documents that will handle each one of my cases. So, if I can just simply use them as the cell editors. This simplifies things for me.
As far as the cell hiding thing, I unfortunetely cannot hide columns and rows, since my readonly cell could be in any location. I agree that column\row hiding would be simple to do. But, the user doesn't want to see the cell at all, and since I cannot do that, I changed the background color
Thanks again for the input. Glad to hear I wasn't completely off the mark
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!