Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to dram on canvas by button click?
How to dram on canvas by button click? [message #1745372] Sat, 08 October 2016 19:38
Alina K. is currently offline Alina K.Friend
Messages: 2
Registered: January 2016
Junior Member
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

Previous Topic:RCP Web Start stops working with Java 7 update 45
Next Topic:Customize treeview expander for HiDpi
Goto Forum:
  


Current Time: Thu Apr 18 10:14:22 GMT 2024

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

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

Back to the top