问题
I have designed a wizard page with a text field using SWT. I want to add a content assist to the text field i.e , when i press 'Ctrl+space', it has to propose the list of data. Any standard method to implement this feature?
回答1:
You can use the JFace ContentProposalAdapter
to do this on a Text
control.
Use something like:
Text textControl = ....
KeyStroke keyStroke = KeyStroke.getInstance("Ctrl+Space");
new ContentProposalAdapter(textControl, new TextContentAdapter(), provider, keyStroke, null);
provider
is a class implementing IContentProposalProvider
this just has one method getProposals
:
@Override
public IContentProposal [] getProposals(String contents, int position)
{
// TODO return array of `ContentProposal` objects appropriate to the contents
}
来源:https://stackoverflow.com/questions/42687493/how-to-add-content-assist-to-text-field-in-wizard-using-swt-java