问题
It's an extension to this question. The combobox is resized but it is showing the last characters of the long string. How would I always force the combobox to show the string from the start? I checked all the provided methods by ComboBox in jface, but none could qualify to do the task. So I am assuming I would have to write a function for it. But how to go about writing it and attaching that value to combobox. Problem : How it is now How I would like it to be. Just upon selection
回答1:
Usually you shoud be able to change the selected text of an editable Combo
/CCombo
with setSelection()
.
For example
combo.setSelection( new Point( 0, 0 ) )
would position the caret at the beginning of the text field of a combo box.
But apparently this doesn't work (any more?) on SWT on Windows (haven't tried other platforms).
After executing this snippet, the text begin end
remains entirely selected.
Also, this is seemingly unrelated to the length of the text. Here the entire text fits the width of the Combo. You can also replace Combo
with CCombo
, they both behave the same.
shell.setLayout( new FillLayout( SWT.HORIZONTAL ) );
Combo combo = new Combo( shell, SWT.NONE );
combo.add( "begin end" );
combo.select( 0 );
combo.setSelection( new Point( 0, 0 ) );
I'd suggest to file a bug against SWT and see what the SWT maintainers say.
来源:https://stackoverflow.com/questions/32816938/combobox-jface-showing-end-of-string-by-default-how-to-show-start-of-long-strin