Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2010
    Posts
    17
    Rep Power
    0

    Default JTable whole thing changes

    Hi, I have a JTable with a CustomTableModel which is loaded up with data contained in a GridCellCalculator. Every time a cell is changed by the user, all the other cells must be recalculated by passing the change to a GridCellCalculator instance. At the moment I have the following in the CustomTableModel

    public void setValueAt(Object value, int row, int col) {
    contents[row][col] = value;
    // The following method is always programatically fired...
    fireTableCellUpdated(row, col);
    }

    Which is passing control to the tableChanged() method that I added to thee CustomTableModel as a TableModelListener. This is firing ok and I can load up my GridCellCalculator class and use it to remake all the JTable contents.

    My question is, after I have new values in my GridCellCalculator class, how do I get all the new values (they will all have changed) back into the CustomTableModel and then get the JTable to completely update all it's cells?

    Many Thanks,
    Markus.

  2. #2
    Join Date
    Dec 2010
    Posts
    17
    Rep Power
    0

    Default Resolved!

    Answering my own question, I just stuck a jtable.repaint() after I've loaded up the CustomTableModel with the new data from my GridCellCalculator class and voila it works!

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    That doesn't make sense to me. Usually after updating the model data, all you need to do is call the correct fireTableXXX method and no repaint is needed. If you're subclassing the DefaultTableModelListener, even this isn't needed.

  4. #4
    Join Date
    Dec 2010
    Posts
    17
    Rep Power
    0

    Default

    Thanks Fubarable and you are exactly right! My jtable.repaint() invokation is NOT the answer. I am invoking fireTableCellUpdated(row, col) in the setValueAt method of the CustomTableModel which allows me to get at new user entered data and recreate my entire set of calculations. I then pass these calculation results to my CustomTableModel and I then invoke fireTableStructureChanged() from the CustomTableModel which nicely forces the JTable to completely update itself, even if i've added extra rows or columns to the CustomTableModel. It is all rather elegant isn't it?

    I'm realize now that if I'm trying to do something in Java and I end up with something that isn't simple, elegant and easy to understand in a java 'way of doing things context' then I've made a mistake!

    Many Thanks,
    Mark.

Similar Threads

  1. the variable thing
    By fleg in forum New To Java
    Replies: 8
    Last Post: 11-02-2010, 03:54 PM
  2. Trying to understand the whole 2D thing.
    By xael in forum Java 2D
    Replies: 4
    Last Post: 10-06-2010, 01:41 AM
  3. please i need help with a simple thing
    By zohdi in forum New To Java
    Replies: 28
    Last Post: 05-30-2010, 01:41 AM
  4. A new thing arrives...
    By ewomack in forum Introductions
    Replies: 3
    Last Post: 10-09-2009, 09:16 PM
  5. PLz i really need help on this final thing
    By jason27131 in forum New To Java
    Replies: 2
    Last Post: 08-03-2007, 02:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •