Re: JTable: How to memorize the width of the columns ?




"johnmmcparland" <johnmmcparland@xxxxxxxxxxxxxx> je napisao u poruci
interesnoj grupi:1156769038.065630.258870@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Dado wrote:
How can I force my application to memorize the column width, so that I
don't
need to set the column with every time I start app?

I'm guessing you change your table width when you've run your
application so here's what to do;

1. add code in so that when the column width has finished being
changed, the program writes this to a file.

2. run your program and change your column widths.

3. change your program to read in the file with the widths and set
column widths accordingly.

hope this helps


I found the next example of saving column properties:
columnNames=new String[table.getColumnCount()];

for (int i=0;i<columnNames.length;i=i+1)
{
columnNames[
i ]=table.getColumnModel().getColumn(i).getHeaderValue().toString();
}

---
data=new String[columnNames.length*table.getRowCount()];
j=0;
for (int i=0;i< table.getRowCount();i=i+1)
{
data[j]=table.getValueAt(i,0).toString();
data[j+1]=table.getValueAt(i,1).toString();
data[j+2]=table.getValueAt(i,2).toString();
j=j+3;//for 3 Cols
}
---

File file = new File("myTable.CSV");
String fileData;
if (file != null)
{
try
{
BufferedWriter bufferedWriter = new BufferedWriter(new
FileWriter(file,true));
PrintWriter fileWriter = new PrintWriter(bufferedWriter);
System.out.println("Column Headers ");
for(int j=0; j < table.getColumnCount(); ++j)
{
fileData=columnNames[ i ];
fileWriter.print(fileData+",");
}
System.out.println("Done.... ");
fileWriter.println("");
System.out.println("Exporting Data ");
for(int i=0; i<table.getRowCount(); ++i)
{
for(int j=0; j &lt; table.getColumnCount(); ++j)
{
fileData = table.getValueAt(i,j).toString();
fileWriter.print(fileData+",");
}
fileWriter.println("");
}
fileWriter.close();
System.out.println("Done.... ");


But I don't understand what is .csv, why that extension and how to read it
?


.


Quantcast