Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / August 2006

Tip: Looking for answers? Try searching our database.

JTable: How to memorize the width of the columns ?

Thread view: 
Dado - 28 Aug 2006 13:13 GMT
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?
johnmmcparland - 28 Aug 2006 13:43 GMT
> 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
Dado - 28 Aug 2006 20:24 GMT
"johnmmcparland" <johnmmcparland@googlemail.com> je napisao u poruci
interesnoj grupi:1156769038.065630.258870@i3g2000cwc.googlegroups.com...

>> How can I force my application to memorize the column width, so that I
>> don't
[quoted text clipped - 12 lines]
>
> 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
?
Michael Rauscher - 29 Aug 2006 06:06 GMT
Dado schrieb:

> I found the next example of saving column properties:

It's an example of saving table data.

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

CSV is an abbreviation for Comma Separated Values or Character Separated
Values. A file in CSV format is a text file which usually contains
records which field-values are separated by a special character e. g. a
comma. The output of the code you quoted in your last post could look
like this:

Name,First Name,Sex
Smith,Trevor,Male
Miller,Marlene,Female

As long there is no really good reason for storing properties in CSV
files, don't do it.

Using java.util.prefs.Preferences your configuration data is stored in
an implementation-depended backing store. E. g. in Windows it's stored
in the registry.

If you don't want an implementation-dependend backing store (because you
want the preferences be editable by an ordinary text editor for example)
you can use java.util.Properties and store/load it to/from a properties
file.

Bye
Michael


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.