Java 增加文本字段的大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2320292/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 06:06:08  来源:igfitidea点击:

Increasing the size of the Text field

javaswt

提问by GuruKulki

I am using org.eclipse.swt.widgets.Text's type of Text field. I want to increase the length of the field. How would I do this?

我正在使用org.eclipse.swt.widgets.Text's 类型的 Text 字段。我想增加字段的长度。我该怎么做?

采纳答案by Chris Dennett

For each field, if your general layout manager is GridLayout, your textbox layout data will be GridData. Pass width and height into the GridData constructor and set it to the textbox (textbox.setLayoutData()), along with the properties about how you want the layout manager to manipulate the field.

对于每个字段,如果您的常规布局管理器是 GridLayout,则您的文本框布局数据将是 GridData。将宽度和高度传递给 GridData 构造函数并将其设置为文本框 (textbox.setLayoutData()),以及有关您希望布局管理器如何操作该字段的属性。

回答by bkritzer

Since Text is a control, it inherits the method: Text.setSize(width, height). This lets you set the actual dimensions of the Text field. Change the width to be something larger. You might also want to keep the height the same by doing something like

由于 Text 是一个控件,它继承了方法:Text.setSize(width, height)。这让您可以设置文本字段的实际尺寸。将宽度更改为更大的。您可能还想通过执行类似的操作来保持高度不变

textField.setSize(width, textField.getSize().y)

textField.setSize(width, textField.getSize().y)

回答by stacker