wood burning stoves*
The moose likes Beginning Java and the fly likes JTable column question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JTable column question" Watch "JTable column question" New topic
Author

JTable column question

michael bradly
Ranch Hand

Joined: Oct 06, 2000
Posts: 112
I'm practicing examples using JTables and am wondering what one line of code refers.
i.e.
TableColumn column=null
for (int i = 0; i<5; i++)
{
column = numberTable.getcolumnModel().getColumn(i);
column.setPreferredWidth(myTableModel.getColumnWidth(i) );
}
I am wondering what the for loop code refers to directly when it comes to determining columns.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
The for loop runs through each column in the table. This code will make a table with 5 columns, nicely modeled.


"JavaRanch, where the deer and the Certified play" - David O'Meara
michael bradly
Ranch Hand

Joined: Oct 06, 2000
Posts: 112
Thanks for the response. My confusion originally stemmed from the fact that there is a getColumnCount() method that created columns for the column model and that that count was not the same as in the for loop. So now I am wondering how the for loop is represented. Does the for loop mean that there are 5 columns in the table model that I can put 5 column models in? Unfortunately my book doesn't do a thourough job explaining this concept at this point.
Regards, Michael
Originally posted by Cindy Glass:
The for loop runs through each column in the table. This code will make a table with 5 columns, nicely modeled.

Michael Hildner
Ranch Hand

Joined: Oct 13, 2000
Posts: 297
I hope I'm not incorrect here, but I think the above code just sets to preferred column size of the first five columns.
This morning I needed to set the columns size to a particular size, not knowing the number of columns:
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Perhaps I am a bit confused. What exactly are you trying to do here?
You have a numberTable and that has a columnModel from which you get the first 5 column from successively.
Then you go to a completely different model called myTableModel and get the width of the corresponding column and set the numberTable column to that width.
When you say that there is a getColumnCount() method that created the columns for the column model, which model are you talking about? The model of the numberTable or the myTableModel which might have a different column count?
You really don't show enough code for me to understand.
michael bradly
Ranch Hand

Joined: Oct 06, 2000
Posts: 112
That resolves my issue. I was a bit confused because the book I was using had a different column number for the Table Column vs. how many were in the overall Table.
Thanks...

Originally posted by Michael Hildner:
[B]I hope I'm not incorrect here, but I think the above code just sets to preferred column size of the first five columns.
This morning I needed to set the columns size to a particular size, not knowing the number of columns:
[/B]

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable column question