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 an array of String
representing TimeZone
IDs.
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) { ... String[] ids = TimeZone.getAvailableIDs(); timezones = new Combo(parent, SWT.SIMPLE); timezones.setVisibleItemCount(5); for (int i = 0; i < ids.length; i++) { timezones.add(ids[i]); } }
Run the Eclipse and open the Clock View again, and a list of time zones will be shown:
It's conventional to set the focus on a particular widget when a view is opened. Implement the appropriate call in the
ClockView's setFocus()
method:public void setFocus() { timezones.setFocus(); }
Run Eclipse and open the Clock View, and the...