简体   繁体   English

选中复选框时将文本框动态添加到窗口

[英]Dynamically add Textbox to Window when checkbox is checked

I'm just figuring out my way around SWT. 我只是想办法解决SWT。 I have a little problem that i cant seem to solve. 我有一个我似乎无法解决的小问题。 I have a check-box in my window. 我的窗口中有一个复选框。 When the check-box is checked, i would like add a multi-line, read-only, text box below it, lets say 200x200. 选中该复选框后,我想在其下方添加一个多行只读文本框,例如200x200。 I want the height of the window to increase to accommodate this text-box. 我希望窗口的高度增加以容纳此文本框。 When the check-box is unchecked I'd like the opposite to happen. 如果取消选中复选框,我会发生相反的情况。

Could you help me with this? 你能帮帮我吗? I can't find an example but maybe I'm not using the right keywords. 我找不到一个例子,但也许我没有使用正确的关键字。 Cheers. 干杯。

--EDIT - 编辑

the.duckman'ss answer was very helpful. the.duckman的回答非常有帮助。 I've managed to get it working to some extent. 我设法使它在某种程度上起作用。 I'm adding a multi-line textbox 480px high. 我要添加一个多行文本框,高度为480px。 How do I automatically resize the window to accommodate the text box? 如何自动调整窗口大小以适应文本框? When the user checks the checkbox, the textbox shows up but the height of the window doesn't increase to accommodate the textbox. 当用户选中该复选框时,文本框会显示,但窗口的高度不会增加以容纳文本框。 My code is a little long so I've put it in PasteBin — http://pastebin.com/01RxKeEr 我的代码是有点长,所以我把它放在引擎收录- http://pastebin.com/01RxKeEr

Thanks. 谢谢。

I recommend looking at the SWT Snippets to every beginner - that's probably the best place to go to with SWT questions. 我建议为每个初学者查看SWT片段 -这可能是SWT问题的最佳去处。

This snippet does exactly what you want. 该代码片段正是您想要的。

Edit 编辑

Ooops, I ignored the second half of your question, sorry. 抱歉,我忽略了您问题的后半部分。 Simply add this line to your listener: 只需将此行添加到您的听众:

shell.setSize(shell.computeSize(SWT.DEFAULT, SWT.DEFAULT));

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

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