向 Eclipse 工具栏添加可调整大小的文本

发布于 2024-10-25 08:45:31 字数 704 浏览 0 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如何视而不见 2024-11-01 08:45:31

控制贡献位于酷栏内。所以除非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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文