So, I can't draw anything on canvas by button click(I see only two lines that I've added in paint listener). How to draw something on canvas(for example, graph of sinus) using button?
Here are snippets of my code...
Canvas canvas = new Canvas(shell, SWT.NONE);
canvas.addListener (SWT.Paint, e -> {
GC gc = new GC(canvas);
canvas.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
int maxX = canvas.getSize().x; int maxY = canvas.getSize().y;
int halfX = (int) maxX / 2; int halfY = (int) maxY / 2;
gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
gc.setLineStyle(SWT.LINE_SOLID);
gc.drawLine(0, halfY, maxX, halfY);
gc.drawLine(halfX, 0, halfX, maxY);
});
......
Button b = new Button(composite, SWT.PUSH); b.setText("Plot");
b.pack();
b.addListener(SWT.Selection, e-> {
GC gc = new GC(canvas);
gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
gc.drawOval(100, 200, 20, 20);
});
//And nothing happens!
canvas.redraw();
[Updated on: Sun, 09 October 2016 05:07]
Report message to a moderator