我正在阅读 TextField 的文档,我发现了一个名为 prefColumnCount 的属性。据我了解,这个属性控制文本字段的大小,但我找不到明确的答案,谷歌搜索也没有得到任何结果。什么是文本栏?它们是如何测量的?有什么我应该知道的不明显的事情吗?
最佳答案
在 TextFieldSkin
中,您可以使用以下属性找到此代码片段:
@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;
}
即它用于通过将属性值乘以 W
的宽度并添加水平插图来计算首选宽度。
关于java - TextField 的 prefColumnCount 属性是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43398185/