Re: JTable: How to memorize the width of the columns ?
- From: "Dado" <mario_zupan@xxxxxxx>
- Date: Mon, 28 Aug 2006 21:24:57 +0200
"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 < 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
?
.
- Follow-Ups:
- Re: JTable: How to memorize the width of the columns ?
- From: Michael Rauscher
- Re: JTable: How to memorize the width of the columns ?
- References:
- JTable: How to memorize the width of the columns ?
- From: Dado
- Re: JTable: How to memorize the width of the columns ?
- From: johnmmcparland
- JTable: How to memorize the width of the columns ?
- Prev by Date: Re: Different height at JComboBox editor and renderer
- Next by Date: Re: Move scrollbar from a JButton
- Previous by thread: Re: JTable: How to memorize the width of the columns ?
- Next by thread: Re: JTable: How to memorize the width of the columns ?
- Index(es):