2

Possible Duplicate:
Java Swing revalidate() vs repaint()

I am working on a database application ( Java + oracle 11g ) and I need to know what and why I need to revalidate/repaint in order to get proper display. I have following components :

      JFrame {
          JCardPanel{
             //card1:
             JPanel {
                JScrollPane1 {
                     { JTable1 }
                }
                JScrollPane2 {
                     { JTable2 }
                }
             }
            //card2:
            JDialog{
               ( login window )
            }
      }

"nested" in this order. The content of JTables changes very often and I don't know how to display them correctly - I am not a swing expert so could someone give me a hint what I need to refresh, how to do it and explain what is happening.

Community
  • 1
  • 1
koleS
  • 1,263
  • 6
  • 30
  • 46

2 Answers2

6

If your TableModels have been created correctly, then all you have to do is update the data in the model and the view will display the changes. This is taken care of for you if you use a DefaultTableModel. If you use a model based on the AbstractTableModel, you must take care to call the appropriate fireTableXXX(...) method after any changes are made to the model. The AbstractTableModel API will show you more about these methods as will the JTable tutorial.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
3

In addition to earlier suggestion of updating model, I would add that if your table is modified such that there are thousands of rows added/deleted at once then you will save some extra painting by calling fireTableDataChanged() after updating the table in bulk.

Ashwinee K Jha
  • 9,187
  • 2
  • 25
  • 19
  • ehhh... no: Bulk or not, as long as the modifications are closed blocks, the more specific fire methods are way better (allow the table to keep state like f.i. selection) – kleopatra Feb 26 '12 at 11:10