Re: JTable -- resizing column widths
I also ran into the same problem, but found a quick work around:
Since this sets the Min, Max, and Preferred to all the same size, Java has
no choice on what size to make things. The one draw back is the user can
no longer resize the columns. Hope that helps!
"Jo Desmet" <firstname.lastname@example.org> wrote:
>In the sun java tutorials they explain how you can resize the columns to
>all cells in that column. All goes well when this is called only once after
>creation (Model or Data is constant).
>However, I work with a dynamic model (data can be loaded, columns can be
>added, ...), and whatever way I choose, the resizing of the columns have
>Way to the strange effects:
>1./ I create the Table with the model, and resize columns: everything ok,
>2./ change the data (using setModel on the table or
>fireTableStructureChanged on the model),
>3./ somehow I resize the columns which as proposed in the sun java
>tutorial. -> first time mostly Ok, second time mostly not.
>4./ resize one of the columns again manually, then repeat 2 and 3 -> first
>time always Ok, second time mostly not
>Places to hook-in the functionality of resizing the columns (as I have tried
>with all the same effect):
>1./ override the tableChanged + dynamicly change the Model
>2./ override the tableChanged + use setModel with a newly created model
>2./ make a method wich first calls fireTableStructureChanged and then
>resizes the columns. This function should be called manually whenever the
>None of them lead me to the expected result.
>Anyone with simular problems?
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center