I have 2 classes, Model class & Panel class having JTable instance. In that Panel class, I did, model_obj.addTableModelListener(this); This model_obj is passed to the JTable instance. From this same class I am populating row in model class. With an action event for a button, I am inserting row into model. There I call rowInsert function from model class which having, fireTableChanged(new TableModelEvent(this)); /// this = Object of model class. which works fine, calling tableChanged method from my Panel class. This even gives me info, such as, event raised is for insertion. In this tableChanged method, I called updateUI() for Panel. All works with no exception anywhere. But inserted row is not getting displayed over Panel. Initially I am having no rows. Please Note : table object is added to the ScrollPane, which in turn added to Panel. Component addition code is perfect. Where can I be wrong ? waiting impatiently !!!
hi, you don't need to call any repaint or update methods. the model should notify the table on its own: http://java.sun.com/docs/books/tutorial/uiswing/events/tablemodellistener.html "Each JTable [(in the Creating a GUI with JFC/Swing trail)] object has a table model that holds its data. When a table model listener is registered on the table model, the listener is notified every time the table model's data changes. The JTable itself automatically uses a table model listener to make its GUI reflect the current state of the table model." chantal
Joined: Mar 12, 2001
Thanx guys for your valuable comments. Indeed problem found to be different. I have added table to Panel. ScrollPane to ScrollPane. Since initially table having no rows Panel as well the ScrollPane were at their min position. After I add row to model, I used to get of type Row Added to the Table, but I could never see that added row, until, I dragged my SplitPane below (resize). It was indeed silly thing to have Panel within scrollpane. Thanx.
Joined: Sep 28, 2000
If your using swing (JTable, JScrollPane, JPanel), then it is necessary to add the table to the scrollpane if you ever want to see any columnheaders. chantal