1

This my new MyJtable

public void addWidget(Book w) {
    datalist.add(w);
    fireTableRowsInserted(datalist.size()-1, datalist.size()-1);

   }

calling class

  MyJtable tv = new MyJtable(a);
        table = new JTable(tv);
        //tv.addWidget(b3);
        JScrollPane pane2 = new JScrollPane(table);

button CLick function

 public void actionPerformed(ActionEvent e)
   {
    MyJtable tv1 = new MyJtable();
    Book b3 = new Book ("Java nutshell-299", "Ajfdfdfdingya2") ;
    if("Add".equals(e.getActionCommand()))
  {
  JOptionPane.showMessageDialog(null,"Add button is clicked");
  tv1.addWidget(b3);
  }

when i click button then i don't see any GUI chnage but if call

tv1.addWidget(b3);

   }

before , i mean on load then i can see the new book but not on button click

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user564477
  • 309
  • 2
  • 9

4 Answers4

3

I see that you add the row to a new table that you've just created inside the actionPerformed method. Usually, we use actions to change/alter already existing GUI components. This might be a reason why you don't see any change on the GUI.

I guess, the table that is displayed in the scroll pane is created with

MyJtable tv = new MyJtable(a);
table = new JTable(tv);

Try adding the row to table (via tv which has to be made an instance variable first) instead of the newly created table.

Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268
  • u mean to say table.addWidget(). I tried that but it says function undefined . i implemented as it was said in this article http://www.informit.com/articles/article.aspx?p=332278&seqNum=4 – user564477 Jan 18 '11 at 12:47
  • 2
    No tv.addWidget() instead of tv1.addWidget(). – jzd Jan 18 '11 at 16:29
  • thanks @jzd dbuddy its done . actually i didn't declare MjTable 's object tv as public and thats why it was not accessible in function and due to that i had to create the new object in function but now thats done. thank you again – user564477 Jan 19 '11 at 05:33
1

Check that you override setValueAt in your concrete implementation of AbstractTableModel. The default implementation is empty.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
1

I think Andreas_D has identified a core issue. You might also have problems because you are overriding AbstractTableModel instead of DefaultTableModel. The DefaultTableModel has many of the event firing methods already completed.

jzd
  • 23,473
  • 9
  • 54
  • 76
1

This my new MyJtable

That is wrong. The table should NOT have an addWidget() method.

All updates to the data should be done directly through the TableModel. Then the TableModel will notify the table to repaint itself when the data changes.

You should never access the data storage used by the TableModel outside of the TableModel itself. I gave you a complete solution when you asked your other question yesterday.

camickr
  • 321,443
  • 19
  • 166
  • 288