jTable problem
Hello folks,
I am writing a small reconciliation program, in which; after initialization of the program, user clicks on a button to import a file, after the file is selected it is read into an Array List, then another button is clicked to read yet another file into an Array List, now that i have two array lists, i want to notify the table to show the Array Lists in seprate columns. which i cant seem to know how to do,
I have read in detail how to notify a table model if something is changed within the model by setting listeners, but how do i notify the table of an external event.
more over i want the table to be hidden when the program is initialized and then become visible once the Array Lists are available, how do i do this.
i can make the code available if the problem is not clear enough yet. ...
Help will be much appreciated......
[887 byte] By [
bilaliza] at [2007-11-27 0:01:14]

Wow! My head is spinning after your explanation!
Steps (Like classic thermodynamics, there IS a zeroth step!):
0. Read the javax.swing.JTable and .table.TableModel APIs.
1. When you construct the JTable, set the variable that holds headers to be two elements in length and the variable that holds data to be zero elements.
2. Next, iterate through your first data structure and place it elements into the first column of the JTable.
3. Do the same with your second data structure.
Thanks for both of the replies guys,
i went through JTable and the TableModel API,
and reading through it, i do understand how to insert the values into rows,
but what i cant understand is, that how do i notify the table, that an external class has created the Array Lists and that its ready to be inserted into the data,
for example the following code
where:
"imismissing" and "ifdsdoesntknow" are the two array lists
Reconcile is a class that hasa method reconcile to perform the reconciliation
private void reconcileButtonActionPerformed(java.awt.event.ActionEvent evt) {
if (imFile == null && ifdsFile == null){
System.out.println("Please select both IFDS & Iron Mountain Files");
} else if (imFile == null || ifdsFile == null){
if (ifdsFile == null){
System.out.println("Please load IFDS media file first");
} else if (imFile == null){
System.out.println("Please load Iron Mountain media file first");
}
} else {
Reconcile recarray1 = new Reconcile();
imismissing = recarray1.reconcile(ifdsarray, imarray);
Reconcile recarray2 = new Reconcile();
ifdsdoesntknow = recarray2.reconcile(imarray, ifdsarray);
}
}
once the lists are produced how do i notify the TableModel. the API only gives listeners to listen an event within the already created table.
Tillerman, I do understand where you are getting at, but as i understand that the table will be initialized when the program starts, calling the ArrayLists, which will be null at that point since no file is loaded, once the files are loaded and the ArrayLists actually have data, how
do i notify the table to re-read the array lists?
Message was edited by:
bilaliz
In the future, Swing related questions should be posted in the Swing forum.
> but what i cant understand is, that how do i notify the table, that an external class has created the Array Lists and that its ready to be inserted into the data
You have to add the data to the TableModel.
Check out the DefaultTableModel. It has methods like addRow() or addColumn().