Time for action – drawing a custom view
An SWT Canvas
can be used to provide custom rendering for a view. As a starting point for drawing a clock, the Canvas
will use drawArc
to create a circle.
- Remove the content of the
ClockView
, leaving behind an empty implementation of thesetFocus
andcreatePartControl
methods. - Run the target Eclipse instance and you will see that the
ClockView
is now empty. - Create a new method called
drawClock
that takes aPaintEvent
, and use the graphics contextgc
from the event to draw the circle. - In the
createPartControl
method, do the following:- Create a
new Canvas
, which is a drawable widget. - Add a
PaintListener
to theCanvas
that uses a method reference to thedrawClock
method.
- Create a
- The code will look like this:
package com.packtpub.e4.clock.ui.views; ...
Get Eclipse Plug-in Development Beginner's Guide - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.