简体   繁体   English

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

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

GXT 3.0.1 GWT 2.5.1 GXT 3.0.1 GWT 2.5.1

I am trying to make a textfield the same height as the button next to it, but it does not work. 我正在尝试使文本框的高度与旁边的按钮相同,但是它不起作用。 I have tried the TextFields own set functions, the cointaner Layout functions and so on. 我尝试了TextFields自己的设置函数,cotantaner Layout函数等。 Nothing seems to work like suspected. 似乎没有什么像怀疑的那样工作。

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);

The snippet does not represent, what I have tried so far. 这段代码并不代表我到目前为止已经尝试过的内容。 The snippet shows in what context I am using the TextField and the Button (Containers). 片段显示了我在什么上下文中使用TextField和Button(容器)。 What am I missing? 我想念什么? Or is it even possible to adjust the height over a fixed value like pixels? 还是有可能在像像素这样的固定值上调整高度? I am quite new to GXT. 我是GXT的新手。

Thank you very much. 非常感谢你。

I have found a CSS-free solution myself. 我自己找到了无CSS解决方案。 But thanks to geert3 for his suggestion to look into the html itself to determine what component have to be adjusted to visualize the correct height. 但是,感谢geert3提出的建议,即调查html本身以确定必须调整哪些组件才能可视化正确的高度。 In the end the "input" field have to be modified. 最后,必须修改“输入”字段。 For this purpose I have written a small class that extends the Textfield itself and provides a method to adjust the input fields height. 为此,我编写了一个小类,扩展了Textfield本身,并提供了一种调整输入字段高度的方法。 Almost every attribute of the TextFields input field can be modified this way. 可以通过这种方式修改TextFields输入字段的几乎每个属性。 Here is the solution: 解决方法如下:

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();
        }
    }

Or you can have the same effect in one line of code. 或者,您可以在一行代码中获得相同的效果。 In the context, that was posted with the question, the solution would be: 在此问题中发布的解决方案是:

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

Try this: 尝试这个:

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

If you want to do this often (ie for many components), you should consider using CSS to style the textfield. 如果您想经常执行此操作(即针对许多组件),则应考虑使用CSS设置文本字段的样式。 This involves: 这涉及:

  1. add a stylename to the textfield 将样式名称添加到文本字段

    searchText.addStyleName("mytextfield");

  2. in your CSS, define the styles for mytextfield class: 在CSS中,定义mytextfield类的样式:

    .mytextfield { line-height: 20px }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM