NSTableColumn autosizing to fit

Discussion in 'Mac Programming' started by McBgnr, Jun 3, 2009.

  1. McBgnr
    Expand Collapse
    macrumors regular

    Apr 13, 2009

    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?
  2. kainjow
    Expand Collapse
    Moderator emeritus


    Jun 15, 2000
    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).
  3. McBgnr
    Expand Collapse
    thread starter macrumors regular

    Apr 13, 2009
    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.

Share This Page