This week's book giveaway is in the Functional programming forum.
We're giving away four copies of A Functional Approach to Java: Augmenting Object-Oriented Java Code with Functional Principles and have Ben Weidig on-line!
See this thread for details.
  • 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
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

cell model and table display

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic