JTable column model issues

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JHuman
    New Member
    • Feb 2009
    • 5

    JTable column model issues

    Hi all. I've defined a custom TableModel so I can use custom types for my JTable. However, because of this, the table's TableColumnMode l is totally out of sync with the model (ie. it isn't populated with any column data at all. No TableColumns or anything). This is annoying, since I need some reference to TableColumn objects (to do some column header rendering stuff).

    Are there any good tutorials or examples that show how to ensure column models are in sync with custom table models, so that when you add data/columns to the model, they are also added to the column model?

    I hope this post is clear.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Nah, the post is not clear to me. You extended DefaultTableMod el and set an instance of that class to be the TableModel of a JTable, right? What is the problem now?

    Comment

    • JHuman
      New Member
      • Feb 2009
      • 5

      #3
      Yes.

      Basically, in the custom model, the columns are represented by a list of custom types. On overriden methods like getColumnName() and getColumnCount( ), I simply interact with this list to return the appropriate value.

      However, the column model of the JTable has no knowledge of this list of custom types. Because addColumn() is never called on it, it is not populated with any TableColumns. This poses a problem, since I want to set the renderers for column headers in the table, but the only way to do that is by calling setHeaderRender er() on TableColumn types, but there aren't any actually being created (since I use a list of custom types).

      How do I fix this? Or am I doing it wrong? Should custom column types be added to a custom column model rather than a custom table model?

      EDIT: basically, I'm looking for a way to ensure that any data in the custom table model is reflected in the default column model.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        See if Sun's tutorial will help. I'm not sure that I fully graps what you are trying to do. Perhaps you just want to define a custom TableCellRender er?

        Comment

        Working...