0

I am currently working on a GUI for a database plugin feature using JFace (cannot use any other method due to threading issues), and am tasked with making the GUI look as similar to the database fields as possible. I need to place an asterisk inside of the text field as shown below:

enter image description here

I'm attempting to use the FieldDecorator method to do this, but this places the asterisk outside of the text field. Is there any way to get it to draw inside of the text field instead?

1 Answer 1

4

You can't get the field decoration to show inside a control.

What you could do is use a Text control without a border and put it in a Composite with a border. The decoration can also be within the composite. Setting the composite background color to match the text will make things look like you want.

Something like:

Composite border = new Composite(composite, SWT.BORDER); 

GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.marginRight = 8;  // Margin at right large enough for your decoration
border.setLayout(layout);

// Set border composite color to match Text background
border.setBackground(border.getDisplay().getSystemColor(SWT.COLOR_WHITE));

Text text = new Text(border, SWT.SINGLE);

ControlDecoration dec = new ControlDecoration(text, SWT.RIGHT | SWT.TOP, border);

dec.setImage(your image);
dec.show();
1
  • I did read this but the feature request was set to low priority: when I get back to implementing it I will accept this answer if it works Aug 25, 2014 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.