English 中文(简体)
GWT TextArea in ScrollPanel in TabLayout 小组——如何达到100%的高度?
原标题:GWT TextArea in ScrollPanel in TabLayoutPanel - how to take 100% of height?
  • 时间:2012-01-14 02:03:30
  •  标签:
  • gwt
  • layout

这里是显示我问题的奇妙智囊团。 它是通常的UIBinder碎块,加上三个植被:塔布莱乌 Panel, ScrollPanel, TextArea. 我希望文本Area能够占用所有可使用的表格空间,我希望它能够有一套可使用的滚动条。 但是,该法典产生了一条案文Area,即两条线。 你们如何解决这一问题? 为什么它无视高峰?

enter image description here

ui:

<!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 + "
");            
        }
        textArea.setText(junk.toString());
    }
}

模块文件只是增加了根基:

public void onModuleLoad() {       
   BugDemoLayout bd = new BugDemoLayout();
   RootLayoutPanel.get().add(bd);
最佳回答

TabLayoutPanel and ScrollPanel both implement the RequireResize interface and automatically resize to the available space using absolute positioning.
You specified a relative height (100%) for the content inside the ScrollPanel. This doesn t work because the size in the parent isn t explicitly set (see here for more details).

So you can either:

  1. Set an explicit size in the ScrollPanel in pixel and then set the Textarea height to 100%.
  2. Extend the TextArea and implement the RequiresResize interface (implement the onResize() method where you set the height/width of the TextArea

The second approach is the cleaner recommend one as it also resizes the TextArea when you resize the browser window. It would look something like that:

文本Area:

public class ResizableTextArea extends TextArea implements RequiresResize {

     public void onResize() {

         int height = getParent().getOffsetHeight();
         int width = getParent().getOffsetWidth();
         setSize(width+"px",height+"px");
     }
}

页: 1 这将确保有一个不间断的<代码>LayoutPanels或Widgets链条,可实施<代码>RequiresResize/ProvidesResize接口,以至您的定制文本Area。

问题回答

您将文本Area放在一个纸浆厂内,但由于文本Area已经具备了可加使用性,因此,纸浆厂是必要的。 如果你拿走雕塑,就应当做罚款(在我测试时,它会奏效)。

我会ski笑这个问题的精干部分,但回答的是滚动部分(因为似乎从未解决过)。

我也存在同样的问题,因此,我在表格中放置了<条码>ScrollPanel,并在表格中添加了<条码>超文本/密码>,该母体的宽度和高度为<条码>。 然后,我使用<代码>panel.add(新的“超文本”);填满。

I also replaced " " with "<br />" in my actual long text string. (That was applicable for my needs).

Now, that s not quite the same thing as a TextArea, of course, but it does allow you to display long running scrolling text inside of a TabLayoutPanel.





相关问题
Very basic WPF layout question

How do I get this listbox to be maxiumum size, i.e. fill the group box its in. I ve tried width="auto" Height="auto", width="stretch" Height="stretch" annoyingly at the moment, it dynamicly sizes to ...

How to align the text to top of TextView?

How to align the text to top of a TextView? Equivalent Android API for Swings setInsets()? that is top of text should start be in (0,0) of TextView <?xml version="1.0" encoding="utf-8"?> <...

Centring a flow in Shoes

Can I center the contents of a flow in Shoes? I know that a paragraph can be centred like: para Centred paragrpah , :align=> center However, this does not work with flows: flow(:align=> ...

Overlaying with CSS

I want to load a website in an iframe, and overlay the website with some hints about the website that is shown. However, i got stuck at the point that the website has a variable passive white space at ...

How do you normally make a program look beautiful? [closed]

How can I make an Application look nice and not like an amateur pulled it together? I mean graphic-wise. Is there some sort of book you can read regarding beautiful program layouts, etc? I put this ...

热门标签