我们在项目中使用Vaadin 6.8.9。我们创建垂直布局的弹出窗口,添加一些标签和按钮。使用白色空格的值增加标签高度
奇怪的是,当一个标签的值包含空格(空格,连字符等)时,它会通过在文本下面添加空格来增加它的高度。对于每个空间,它看起来像是最后一个空行被添加。对于连字符而言,它可能更少一半。可以这么说,a a a a a a a a
消息在屏幕上占用了大量空白空间(并且标签越多越差)。
创建窗口没有魔法。我们只是创建新窗口并将其宽度设置为600像素。我们没有为窗口和标签设置任何其他属性。我无法在新测试的Vaadin项目上重现它,所以我想问题必须与我们的应用程序,但我不能指出它。
下面是一个这样的标签生成的示例代码:
<div style="height: 180px; width: 54px; overflow: hidden;
padding-left: 0px; padding-top: 0px;">
<div style="float: left; margin-left: 0px;">
<div class="v-label" style="width: 108px;">
a a a a a a a a a a
</div>
</div>
</div>
为什么第一个DIV是180像素高,如果标签值是只有一条线?高度计算机制位于何处,并且是否可以使用Vaadin API进行更改?
编辑: 这里的要求弹出窗口代码,但我敢肯定问题是不是与此窗口。
public class InfoNotification extends Window {
/* Few members and constructor. Members assignment and run init() only. */
/** This method is run from constructor */
private void init() {
setModal(true);
setResizable(false);
setStyleName("info_notification");
okButton = new Button();
okButton.addListener(getCloseButtonListener(this));
okButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
okButton.setCaption(okLabel != null ? okLabel : SessionData
.getMessage("infoNotification.okLabel"));
initLayout();
}
private void initLayout() {
VerticalLayout componentLayout = (VerticalLayout) getContent();
componentLayout.setWidth(600, UNITS_PIXELS);
if (messages != null) {
for (String message : messages) {
componentLayout.addComponent(new Label(message));
}
}
componentLayout.addComponent(okButton);
componentLayout.setComponentAlignment(okButton,
Alignment.BOTTOM_CENTER);
setReadOnly(false);
}
public Button.ClickListener getCloseButtonListener(final Window window) {
return new Button.ClickListener() { /* listener code */ };
}
}
当我现在思考它,它看起来像窗口为600像素宽,但Vaadin出于某种原因认为是非常薄(像素夫妇也许?)。结果是它保留了更多的高度,因为它检测到很多换行符。事实上,根本没有换行符,空闲空间没有被使用。但这只是我的猜测。编辑2:我发现,当我从组件中删除所有大小设置,标签只有87px宽。我发现,当我从组件中删除所有大小设置时,标签只有87px宽。设置不同的标签宽度不会改变。
private void initLayout() {
VerticalLayout componentLayout = (VerticalLayout) getContent();
componentLayout.setWidth(600, UNITS_PIXELS);
componentLayout.setSizeUndefined(); // Removes all size settings.
// Rest of method is the same.
}
通过HTML渲染Vaadin:
<div style="height: 36px; width: 87px; overflow: hidden; padding-left: 0px; padding-top: 0px;">
<div style="float: left; margin-left: 0px;">
<div class="v-label" style="width: 87px;">a a a a a a a a a a</div>
</div>
</div>
您可以向我们展示带有用于添加标签的容器的Java代码吗? 它不应该这样(当然不取决于空白的数量),一定有其他事情出错或干扰它 –