PDA

View Full Version : NSTableColumn autosizing to fit




McBgnr
Jun 3, 2009, 11:15 PM
Hello,

I have a NSTableView which has 2 columns. First columns contains strings. Some of these strings are long and are not visible completely in the column. I have also added HorizontalScroll bar to the TableView but no use. It scrolls the contents of the TableView but not of the column.

How can I request TableColumn to resize so that the longest string is the column is completely visible. The min and max width parameters of the TableColumn are set correctly. I have also tried using the Col. Sizing style but it did not help either. Any suggestions?



kainjow
Jun 4, 2009, 12:33 AM
I don't think there's a built-in way to do this, if I'm understanding it correctly. You could just use NSAttributedString to get the width of the string at the font (via the tablecolumn's datacell) and then set the column's width to that (plus a bit more probably for spacing).

McBgnr
Jun 4, 2009, 05:03 AM
I was wondering that there might be some built in way for this :-(. I will give a try to the other method using the attributed string.