combobox jface showing end of string by default. How to show start of long string

妖精的绣舞 提交于 2019-12-25 06:36:52

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!