xav9211
xav9211

Reputation: 201

Set CONSTRAINED_RESIZE_POLICY for columns without first (for number of row) in tableView JavaFx

I have tableView with first column for row number. I would like to set CONSTRAINED_RESIZE_POLICY for all columns without first.

I made:

//First column implementation
column.setPrefWidth(40);
column.setResizable(false);
... //Make other columns
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

So I have first column with width I chose but other are wider than without last line in code above but still there is one additional void column.

And I have another question because I looked for resizing column to length of the longest text in column (I need it for first column) but I only found old answers with very long and tricky solutions. Is there any simple solution (method) to do it?

Edit: I found that when I try to manually resize columns, that they resize properly (as they should with CONSTRAINED) after only click to resize one of columns so I have a question, why they didn't resize from the start like I described above but after trying to manual resize. I think that problem is with setResizable false on first column but how can I repair this?

Upvotes: 4

Views: 7153

Answers (1)

xav9211
xav9211

Reputation: 201

I found solution. To make other columns CONSTRAINED_RESIZE_POLICY there must be set size of the first column like below:

column.setMinWidth(40);
column.setMaxWidth(40);

and it's working without line setResizable(false).

Upvotes: 3

Related Questions