Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsHow do I make a rectangle clickable?
https://www.eclipse.org/forums/index.php/mv/msg/77342/240818/#msg_240818
a mouse click. I tried the following and it does not work - the
rectangle does not draw when used as the contents of the Clickable.
Could somone please explain what it means for a Clickable to have
contents. I assumed that the contents of a clickable would the the
figure shown and that the Clickable would simply be a wrapper on top of
the figure handling the mouse actions, but it seems that's not the case.
Canvas canvas = new Canvas(parent, SWT.NONE);
LightweightSystem lws = new LightweightSystem(canvas);
Figure root = new Figure();
RectangleFigure rect = new RectangleFigure();
Clickable click = new Clickable(rect);
click.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
System.out.println("actionPerformed()");
}
});
Bryan]]>Bryan Hunt2008-01-19T03:21:51-00:00Re: How do I make a rectangle clickable?
https://www.eclipse.org/forums/index.php/mv/msg/77342/240823/#msg_240823
Originally posted by: shady_86.sify.com
there is a predefined org.eclipse.draw2d.Button.Button()
try to use it, i am not sure but it may work..,]]>2008-01-19T08:03:48-00:00Re: How do I make a rectangle clickable?
https://www.eclipse.org/forums/index.php/mv/msg/77342/240894/#msg_240894
AN other way to achieve what you want is by adding a Draw2D MouseListener
to your rectangle.
The MouseListener interface allows you to respond to mouse up, mouse down
and mouse double click events.
Hope this help
Manu http://manuelselva.wordpress.com/]]>Manuel Selva2008-01-23T08:05:01-00:00Re: How do I make a rectangle clickable?
https://www.eclipse.org/forums/index.php/mv/msg/77342/240949/#msg_240949
> Hi Bryan,
> AN other way to achieve what you want is by adding a Draw2D MouseListener
> to your rectangle.
> The MouseListener interface allows you to respond to mouse up, mouse down
> and mouse double click events.
Hello Bryan,
You may like to have a look at
org.eclipse.draw2d.LightweightSystem class.
Neeraj.]]>Neeraj Bhusare2008-01-25T06:55:44-00:00Re: How do I make a rectangle clickable?
https://www.eclipse.org/forums/index.php/mv/msg/77342/241073/#msg_241073
Originally posted by: Gerhard.Hinterndorfer.pedrics.at
Hallo Bryan,
use addMouseListener:
rect.addMouseListener(new MouseListener.Stub(){
public void mousePressed(MouseEvent me){
System.out.println("Mouse pressed on rect:" +"
x-Pos:"+me.x+" y-Pos:"+me.y);
});
Hope that helps.
cheers
Gerhard
Bryan Hunt schrieb:
> I would like to display a rectangle on a canvas and have it respond to a
> mouse click. I tried the following and it does not work - the rectangle
> does not draw when used as the contents of the Clickable. Could somone
> please explain what it means for a Clickable to have contents. I
> assumed that the contents of a clickable would the the figure shown and
> that the Clickable would simply be a wrapper on top of the figure
> handling the mouse actions, but it seems that's not the case.
>
> Canvas canvas = new Canvas(parent, SWT.NONE);
> LightweightSystem lws = new LightweightSystem(canvas);
> Figure root = new Figure();
> RectangleFigure rect = new RectangleFigure();
> Clickable click = new Clickable(rect);
> click.addActionListener(new ActionListener()
> {
> public void actionPerformed(ActionEvent arg0)
> {
> System.out.println("actionPerformed()");
> }
> });
>
> rect.setBounds(new Rectangle(10, 10, 100, 100));
> root.add(click);
> lws.setContents(root);
>
> Bryan
>]]>2008-01-29T07:51:28-00:00