我們在項目中使用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代碼嗎? 它不應該這樣(當然不取決於空白的數量),一定有其他事情出錯或干擾它 –