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?
You don’t need to set the width. Unless the
HorizontalAlignmentisStretch(which is the default) The width of aTextBlockautomatically adjusts to the size of the text it contains (as long as there is enough space to contain theTextBlockof course). So you just need to set theHorizontalAlignmenttoLeft,RightorCenter