且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何更新SWT组合框中的项目列表?

更新时间:2023-01-13 14:19:57

不幸的是,SWT组件没有这样的方法。在Swing中,这将很容易在PopupMenuListener接口的帮助下。

我可以想到的解决办法是实现一个MouseListener和一个KeyboardListener(由于可以通过按空格打开组合框),所以你当这两个事件发生时,可以至少更新您的组合框列表。


I have a UI with a Combo box. The list of items, which can be chosen, has to be refreshed every time the combo is about to open the list.

Is there any way - i.e. to add a listener which will inform UI that Combo is about to open?

Unfortunately I am not able to observe model to update the list when it changes.

Unfortunatelly there is no such method for SWT Components. In Swing it would be easy with the help of the PopupMenuListener Interface.
A workaround I can think of would be to implement a MouseListener and a KeyboardListener (As Comboboxes can be opened by pressing 'space') so you can at least update your Combobox List when those two Events take place.