這是一個模擬UI,展示了我的問題。這是通常的UIBinder樣板,加上三個小部件:TabLayoutPanel,ScrollPanel,TextArea。我希望TextArea佔用選項卡的所有可用空間,並且如果它不適合,我希望它具有滾動條。但是這段代碼產生了兩行高的TextArea。你如何解決這個問題?爲什麼忽略了身高?GWT TextArea在TabLayoutPanel的ScrollPanel中 - 如何取得100%的高度?
在ui.xml文件:
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" xmlns:g="urn:import:com.google.gwt.user.client.ui">
<ui:style>
.scrollPanel {
height: 100%;
}
.textArea {
height: 100%;
}
</ui:style>
<g:TabLayoutPanel barHeight="20" barUnit='PX'>
<g:tab>
<g:header>Text Area</g:header>
<g:ScrollPanel styleName='{style.scrollPanel}'>
<g:TextArea ui:field='textArea' styleName='{style.textArea}'></g:TextArea>
</g:ScrollPanel>
</g:tab>
</g:TabLayoutPanel>
</ui:UiBinder>
和Java文件中:
package com....client;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.ResizeComposite;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.Widget;
public class BugDemoLayout extends ResizeComposite {
private static BugDemoLayoutUiBinder uiBinder = GWT.create(BugDemoLayoutUiBinder.class);
interface BugDemoLayoutUiBinder extends UiBinder<Widget, BugDemoLayout> {}
@UiField TextArea textArea;
public BugDemoLayout() {
initWidget(uiBinder.createAndBindUi(this));
StringBuilder junk = new StringBuilder();
for (int i=1; i<300; i++) {
junk.append("Line " + i + "\n");
}
textArea.setText(junk.toString());
}
}
的模塊文件只是將用戶界面到根:
public void onModuleLoad() {
BugDemoLayout bd = new BugDemoLayout();
RootLayoutPanel.get().add(bd);
我喜歡這一點,它幾乎可以工作。問題在於初始佈局。起初UI看起來像之前,但是當我調整窗口大小來觸發onResize()時,那麼自定義TextArea會根據需要展開。如何在開始時獲得正確的佈局?我嘗試在將所有內容添加到RootLayoutPanel後手動調用onResize - 不起作用。顯然有一些延遲,因爲如果我把這個相同的電話放在延遲的計時器中,它會工作......但是這一切都變得很難看。 – 2012-01-14 17:58:01
正常情況下,「RootLayoutPanel」應負責在呈現/構造時實現「RequiresResize」接口的子部件上調用onResize()。這實際上應該照顧最初的佈局。我很驚訝,它不適用於你的情況。你如何構建TabLayoutPanel?手動調用''onResize()''將不起作用,因爲該小部件尚未連接到DOM。 (更多細節見[這裏](http://markmail.org/message/waanbhkstg7zpad2))。您可以嘗試在應該修復它的TabLayoutPanel上調用foreceLayout()。 – 2012-01-14 18:26:42
設置我的測試應用程序的代碼很簡單,我會在第二個問題中加入。它創建這個小部件並將其添加到'RootLayoutPanel'。 – 2012-01-14 22:43:55