使用Java,如何获取“ActualWidth” TextBlock 的文本并使用它?
参见主题标题。
我在 Java 中有一个方法可以绘制 TextBlock 元素:
public void drawTextBlock(String text) {
Element textBlock = new Element("TextBlock", Ns.getDefaultNamespace());
textBlock.setAttribute(new Attribute("Text", text));
}
但是,TextBlock
的 Width
必须与我提供给它的文本宽度完全相同。
这将如何完成?
See subject title.
I have a method in Java that draws a TextBlock element:
public void drawTextBlock(String text) {
Element textBlock = new Element("TextBlock", Ns.getDefaultNamespace());
textBlock.setAttribute(new Attribute("Text", text));
}
However, the Width
of the TextBlock
must be exactly as wide as the width of the text I give to it.
How would this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要设置宽度。除非
HorizontalAlignment
为Stretch
(这是默认值),TextBlock
的宽度会自动调整为它包含的文本的大小(只要当然,因为有足够的空间来容纳TextBlock
)。因此,您只需将HorizontalAlignment
设置为Left
、Right
或Center
You don't need to set the width. Unless the
HorizontalAlignment
isStretch
(which is the default) The width of aTextBlock
automatically adjusts to the size of the text it contains (as long as there is enough space to contain theTextBlock
of course). So you just need to set theHorizontalAlignment
toLeft
,Right
orCenter