向 Eclipse 工具栏添加可调整大小的文本
在 Eclipse RCP 应用程序中,我想向工具栏添加一个文本小部件,每当用户更改应用程序窗口的大小时,该文本小部件就会动态更改。我创建了一个 ControlContribution 并将其添加到 plugin.xml 中的菜单扩展点。
ControlContribution 由保存文本的 Composite 组成。合成的布局设置为网格布局,文本的布局数据是启用了抓取多余水平空间的网格数据。
但是,文本始终保持相同的大小。我还通过向其添加侦听器来检查在调整工具栏大小时是否通知复合材料。监听者永远不会被调用。 如何调整文本大小?
ControlContribution 的 createControl()
方法中的代码:
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout());
text = new Text(composite, SWT.SINGLE | SWT.BORDER);
GridData gridDataText = new GridData();
gridDataText.grabExcessHorizontalSpace = true;
gridDataText.horizontalAlignment = GridData.FILL;
text.setLayoutData(gridDataText);
In an Eclipse RCP Apllication, I would like to add a text widget to the toolbar, that dynamically changes whenever the user changes the size of the application window. I created a ControlContribution and added it to the menu extension point in the plugin.xml.
The ControlContribution consists of a Composite that holds the text. The composite's layout is set to a grid layout, and the text's layout data is a grid data with grabbing excess horizontal space enabled.
However, the text always stays the same size. I also checked if the composite is notified when the toolbar is resized by adding a listener to it. The listener is never called.
How can I get the text to resize?
Code from the createControl()
method of the ControlContribution:
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout());
text = new Text(composite, SWT.SINGLE | SWT.BORDER);
GridData gridDataText = new GridData();
gridDataText.grabExcessHorizontalSpace = true;
gridDataText.horizontalAlignment = GridData.FILL;
text.setLayoutData(gridDataText);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
控制贡献位于酷栏内。所以除非Coolbar占用更多的空间,否则贡献就不可能更大。您需要抓住 Coolbar(当创建控件时,遍历父层次结构),然后更改它的大小并更新整个布局
The control contribution is inside a coolbar. So unless the Coolbar takes more space, the contribution cannot grow bigger. You need to grabe the Coolbar (when you control is being created, walk thru the parent hierarchy) and then change the size of it and update the whole layout