Hi pple,
am writing a program whereby i read some values from a file and write them on a table.
The proble is i want to get the last value recorded in the table. anyone who can help me with the logic?
thanks
Printable View
Hi pple,
am writing a program whereby i read some values from a file and write them on a table.
The proble is i want to get the last value recorded in the table. anyone who can help me with the logic?
thanks
Hi,
Go thru the Javadoc.This method is used for fetching the rec.
public Object getValueAt(int row,
int column)Returns the cell value at row and column.
Note: The column is specified in the table view's display order, and not in the TableModel's column order. This is an important distinction because as the user rearranges the columns in the table, the column at a given index in the view will change. Meanwhile the user's actions never affect the model's column ordering.
Parameters:
row - the row whose value is to be queried
column - the column whose value is to be queried
Returns:
the Object at the specified cell
Thanks for the reply but i think i wasnt clear enough for u t understand what i want :-(
The table has 50 rows and the user can fill it upto whatever row. my problem is,i have no specific row and column because the data varries depending on the user.
I want to use the last value keyed in or rather recorded for the purpose of initializing my calculations from previously recorded values.
Any idea now???
Hi,
You are having method called getRowCount().
Say if it returns rowcount as four but,java starts counting from index 0.
Ex:
RowCount is 4 and column count is 1
That means for retrival of last row and 1 column value then
you have to pass
table.getValueAt(3,0) and it will return the last row value.Is it clear?
-Regards
Ramya
Please expound abit coz i have tried to use getRowCount() and this gives me the total number of rows in the table which is not my interest.
The table has 50 rows but it might be filled upto the 10th row,that depends on the amount of data available.
How can i get the value of that cell which i dont know??
cheerz!
Hi,
One small suggestion.Keep a counter during fileread.when enters value into table and comes out,then u keep that as a table rowcount.
Please send ur piece of code if u have not got what iam saying
-Regards
Ramya
Sounds like a good idea but i dont know how to go about it.
The code below shows how i read the file into the table.
check it out and tell me where i can fix the counter.
ThanksCode:File f = new File("Xenon.temp");
try {
String aLine;
int ro = 0;
String t, p;
FileInputStream fis = new FileInputStream(f);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
//Read each line of the file
while ((aLine = br.readLine()) !=null) {
//Tokenize line into field values
StringTokenizer st = new StringTokenizer(aLine, " ");
if (st.countTokens() >= 2){
t= st.nextToken();
p= st.nextToken();
} else {
break;
}
Xenon.setValueAt(t,ro ,0);
Xenon.setValueAt(p,ro ,1);
ro++;
}
br.close();
fis.close();
}catch (IOException e) {
e.printStackTrace();
}
Hi,
Ur variable ro will have know the no of lines in file.U can take that many number of rows will be in table know?
-Regards
Ramya
when i print it out on the screen i get a null :confused:
Hi,
What you printed?
I asked you to print "ro" value.
Check the table whether all the file content ort loaded or not.
-Regards
Ramya
Thanks alot i finally figured it out. This is how i was doing it :
But then i realised that getValueAt starts from index 0Code:String num = (String) Xenon.getValueAt(ro,1);
System.out.print(num );
so the value i want must be ro-1
Thanks for shading some light :)