Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » how to select particular rectangle box from canvas?( I have develop simple example base on SWT. Now I want to select a particular rectangle using selection or any other event? how to give selection event to particular rectangle?)
icon8.gif  how to select particular rectangle box from canvas? [message #1748238] Mon, 21 November 2016 13:21 Go to next message
Sumit Fataniya is currently offline Sumit FataniyaFriend
Messages: 12
Registered: July 2016
Junior Member
Qes: I have develop simple example base on SWT. Now I want to select a particular rectangle using selection or any other event? how to give selection event to particular rectangle?

Code:

public class DrawRoundRectangle {
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display, SWT.SHELL_TRIM);
shell.setText("Canvas Example");

shell.setLayout(new GridLayout(1, true));

final Canvas canvas = new Canvas(shell, SWT.NONE);
canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
canvas.setLayout(null);

canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
// Point p = canvas.getSize();
for (int i = 0; i < 10; i++) {
// e.gc.drawRoundRectangle(10, 10, e.width, e.height, 0, 0);

e.gc.drawRoundRectangle((6 * i), (6 * i), e.width
- (14 * i), e.height - (14 * i), 0, 0);
e.gc.drawText("", (6 * i), (6 * i));
}

}
});

shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
Re: how to select particular rectangle box from canvas? [message #1748422 is a reply to message #1748238] Wed, 23 November 2016 00:53 Go to previous message
Eclipse UserFriend
When drawing on a canvas, you are responsible for managing your objects. SWT is just manipulating a bitmap on your behalf: it doesn't know that you're manipulating some model. So you would need to add a MouseListener and then map the x,y back into your object model.

For a higher-level object framework, take a look at draw2d or its much more complex bigger brother, GEF, or JavaFX.
Previous Topic:how to select particular rectangle box from canvas?
Next Topic:how to solve label and button size when zooming character in View?
Goto Forum:
  


Current Time: Tue Mar 19 08:18:17 GMT 2024

Powered by FUDForum. Page generated in 0.02150 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top