簡體   English   中英

GXT3-TextField的高度。 如何使TextFields的高度更大?

[英]GXT3 - TextField height. How to make a TextFields height bigger?

GXT 3.0.1 GWT 2.5.1

我正在嘗試使文本框的高度與旁邊的按鈕相同,但是它不起作用。 我嘗試了TextFields自己的設置函數,cotantaner Layout函數等。 似乎沒有什么像懷疑的那樣工作。

VerticalLayoutContainer layout = new VerticalLayoutContainer();
HBoxLayoutContainer searchContainer = new HBoxLayoutContainer();
searchContainer.setPadding(new Padding(5));
searchContainer.setPack(BoxLayoutPack.CENTER);
BoxLayoutData boxLayout = new BoxLayoutData(new Margins(0, 5, 5, 0));
searchText = new TextField();
searchButton = new TextButton("Search");
searchContainer.add(searchText, boxLayout);
searchContainer.add(searchButton, boxLayout);
searchContainer.setBorders(true);
layout.add(searchContainer);

這段代碼並不代表我到目前為止已經嘗試過的內容。 片段顯示了我在什么上下文中使用TextField和Button(容器)。 我想念什么? 還是有可能在像像素這樣的固定值上調整高度? 我是GXT的新手。

非常感謝你。

我自己找到了無CSS解決方案。 但是,感謝geert3提出的建議,即調查html本身以確定必須調整哪些組件才能可視化正確的高度。 最后,必須修改“輸入”字段。 為此,我編寫了一個小類,擴展了Textfield本身,並提供了一種調整輸入字段高度的方法。 可以通過這種方式修改TextFields輸入字段的幾乎每個屬性。 解決方法如下:

public class SearchTextField extends TextField {    

        public SearchTextField(){
            super();
        }

        public void setInputHeight(int heightValue) {
            getInputEl().getStyle().setHeight(20, Unit.PX);
        }

        public String getInputHeight() {
            return getInputEl().getStyle().getHeight();
        }
    }

或者,您可以在一行代碼中獲得相同的效果。 在此問題中發布的解決方案是:

searchText.getCell().getInputElement(searchText.getElement()).getStyle().setHeight(20, Unit.PX);

嘗試這個:

searchText.getElement().getStyle().setLineHeight(20, Unit.PX);

如果您想經常執行此操作(即針對許多組件),則應考慮使用CSS設置文本字段的樣式。 這涉及:

  1. 將樣式名稱添加到文本字段

    searchText.addStyleName("mytextfield");

  2. 在CSS中,定義mytextfield類的樣式:

    .mytextfield { line-height: 20px }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM