简体   繁体   English

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

[英]Adding a resizable Text to Eclipse toolbar

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. 在Eclipse RCP Apllication中,我想向工具栏添加一个文本小部件,只要用户更改应用程序窗口的大小,该小部件就会动态更改。 I created a ControlContribution and added it to the menu extension point in the plugin.xml. 我创建了一个ControlContribution,并将其添加到plugin.xml中的菜单扩展点。

The ControlContribution consists of a Composite that holds the text. ControlContribution由包含文本的Composite组成。 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: 来自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);

The control contribution is inside a coolbar. 控件的贡献在一个coolbar内部。 So unless the Coolbar takes more space, the contribution cannot grow bigger. 因此,除非Coolbar占用更多空间,否则贡献不会增加。 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 您需要抓住Coolbar(在创建控件时,遍历父级层次结构),然后更改其大小并更新整个布局

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

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