[英]Labels alignment behaves weird
I have a panel that contains two labels. 我有一个包含两个标签的面板。 Such panels are used in a statistics block as "name:value".
此类面板在统计信息块中用作“名称:值”。 But name's length is different for every entry and UI looks ugly at the end.
但是每个条目的名称长度都不同,并且UI的结尾看起来很丑。 I decided to get the size of the biggest label and set
setPrefWidth()
for all labels in the column to that size. 我决定获取最大标签的大小,并将列中所有标签的
setPrefWidth()
设置setPrefWidth()
大小。 But UI starts looking weird at the end. 但是UI最终开始看起来很奇怪。
Here is what I have: 这是我所拥有的:
Here is the code of such panel: 这是该面板的代码:
public class StatLine extends HBox {
private Label name;
private Label value;
public StatLine(String name) {
super();
this.name = new Label(name);
this.value = new Label("99999");
this.name.setPrefWidth(25);
this.getChildren().addAll(this.name, this.value);
}
}
Without setPrefWidth()
, my result now is the following: 没有
setPrefWidth()
,我的结果如下:
Name1: 99999 Name3: 99999
Long Name: 99999 Name31: 99999
Name2: 99999 Longest3: 99999
The result I want to get at the end: 我想得到的结果是:
Name1: 99999 Name3: 99999
Long Name: 99999 Name31: 99999
Name2: 99999 Longest3: 99999
How can I achieve this? 我该如何实现?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.