开发者

Adding a resizable Text to Eclipse toolbar

开发者 https://www.devze.com 2023-02-19 05:22 出处:网络
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

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开发者_JAVA技巧, 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. 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号