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;
}
即:
這是(大約)字符數。 (大概是因爲在大多數字體中,物理寬度取決於文本中出現的實際字符。) –