- Eclipse Plug-in Development:Beginner's Guide(Second Edition)
- Dr Alex Blewitt
- 253字
- 2021-07-14 10:36:29
Time for action – getting in focus
To allow the time zone of the clock widgets to be changed, a drop-down box (known as Combo
) as well as a Button
will be added to the view. The Combo
will be created from a set of ZoneId
instances.
- Create a
timeZones
field in theClockView
class:private Combo timeZones;
- At the end of the
createPartControl
method, add this snippet to create the drop-down list:public void createPartControl(Composite parent) { ... timeZones = new Combo(parent, SWT.DROP_DOWN); timeZones.setVisibleItemCount(5); for (String zone : ZoneId.getAvailableZoneIds()) { timeZones.add(zone); } }
- Run the target Eclipse and open the Clock View again; a list of time zone names will be shown in a drop-down:
- It's conventional to set the focus on a particular widget when a view is opened. Implement the appropriate call in the
ClockView
methodsetFocus
:public void setFocus() { timeZones.setFocus(); }
- Run Eclipse and show the Clock View; the time zone drop-down widget will be focused automatically.
What just happened?
Every SWT Control
has a setFocus
method, which is used to switch focus for the application to that particular widget. When the view is focused (which happens both when it's opened and also when the user switches to it after being in a different view), its setFocus
method is called.
Note
As will be discussed in Chapter 7, Creating Eclipse 4 Applications, in E4 the method may be called anything and annotated with the @Focus
annotation. Conventionally, and to save sanity, it helps to call this method setFocus
.
推薦閱讀
- The Modern C++ Challenge
- JavaScript 從入門到項目實踐(超值版)
- JavaScript Unlocked
- jQuery從入門到精通 (軟件開發視頻大講堂)
- Spring核心技術和案例實戰
- Unity 2017 Mobile Game Development
- Java語言程序設計教程
- Mastering Elasticsearch(Second Edition)
- Python編程:從入門到實踐(第3版)
- Learning VMware vSphere
- JavaScript重難點實例精講
- 測試架構師修煉之道:從測試工程師到測試架構師(第2版)
- Lua Quick Start Guide
- Python算法設計與分析
- 零基礎玩轉Python