2017-04-13 18 views
1

我正在閱讀TextField的文檔,並且我遇到了一個名爲prefColumnCount的屬性。據我瞭解,這個屬性控制着文本字段的大小,但我找不到明確的答案,並且google搜索結果什麼也沒有。什麼是文本列?他們如何衡量?有什麼不明顯的我應該知道嗎?什麼是TextField的prefColumnCount屬性?

@Override 
protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) { 
    TextField textField = getSkinnable(); 

    double characterWidth = fontMetrics.get().computeStringWidth("W"); 

    int columnCount = textField.getPrefColumnCount(); 

    return columnCount * characterWidth + leftInset + rightInset; 
} 

即:

+0

這是(大約)字符數。 (大概是因爲在大多數字體中,物理寬度取決於文本中出現的實際字符。) –

回答

2

TextFieldSkin您可以使用屬性發現此代碼段它用於通過將屬性的值乘以W的寬度並添加水平插入來計算首選寬度。