A JTable Question?
Hi
I always have problems with JTable. I dont know why i dont understand it. Well here is my problem..
I dont understand how to use TableModel with JTable :( .. i tried it lot but in vain.
rightnow i'm puttin data like this: JTable tbl = new JTable(Vector data, Vector Columns);
Now the priblem is that how can i again put data in that JTable, what method i use which accept Vector. Or is yhere any other method.
At run run time if change the dat in Jtable whether it will done automatically or i have to call UpdateUI or any other method.
Thanks
[590 byte] By [
jawadaha] at [2007-11-27 7:57:52]

Take a look at this:
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
Reading this article solves all of your problems. There's no need to manually update the UI. If you use a TableModel (which is the best method), table automatically updates when you modify the assigned TableModel.
By the way, "Swing related questions should be posted in the Swing forum". ;)
> I dont understand how to use TableModel with JTable :( .. i tried it lot
> but in vain
If you currently not able to implement your own TableModel, you can use DefaultTableModel.
Vector data = ...;
Vector column = ...;
DefaultTableModel tblModel = new DefaultTableModel(data, column);
JTable tbl = new JTable(tblModel);
to modify your data at runtime:
tblModel.addRow(newRow);
see complete API docs here:
http://java.sun.com/javase/6/docs/api/javax/swing/table/DefaultTableModel.html
thnks Guys for the help.. you solved my 80% problem.
Heres wat i understand that when put data to addRow(row) it will automatically update the JTable and i dont have to refresh it.
There is one more tiny question: After calling the dispose(); of any component how to call it back, e.g. i call dispose(); of Internal frame then how to call it back in JDesktopPane.
I know i've to ask the question in Swing forum but these are the initial level problems thats why i'm asking here
If u dont want to dispose, hide the frame. iframe.setVisible(false);
> There is one more tiny question: After calling the
> dispose(); of any component how to call it back, e.g.
> i call dispose(); of Internal frame then how to call
> it back in JDesktopPane.
What "call it back" means? If you want to show the internal frame again, for example, you must just hide it. dispose(); completely erases the frame from the memory, so you need to create it again. If you are sure that your application is going to hide and show a frame frequently, just hide it by calling setVisible(false);.
> I know i've to ask the question in Swing forum but
> these are the initial level problems thats why i'm
> asking here
I know, but these problems must also be asked in the Swing forum. It helps making the whole forum cleaner.
What "call it back" means? If you want to show the internal frame again, for example, you must just hide it. dispose(); completely erases the frame from the memory, so you need to create it again. If you are sure that your application is going to hide and show a frame frequently, just hide it by calling setVisible(false);.
not completely true... it's only release native screen resource and mark as undisplayable. to really release its memory, set the reference to null and wait until gc do the cleaning.
here is the documentation:
Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. That is, the resources for these Components will be destroyed, any memory they consume will be returned to the OS, and they will be marked as undisplayable.
The Window and its subcomponents can be made displayable again by rebuilding the native resources with a subsequent call to pack or show. The states of the recreated Window and its subcomponents will be identical to the states of these objects at the point where the Window was disposed (not accounting for additional modifications between those actions).
> not completely true... it's only release native> screen resource and mark as undisplayable. to really> release its memory, set the reference to null and> wait until gc do the cleaning.Thanks for the tip. Sorry about my mistake.