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);
	        	int maxX = canvas.getSize().x; int maxY = canvas.getSize().y;
	     	    int halfX = (int) maxX / 2; int halfY = (int) maxY / 2;
	    	    gc.drawLine(0, halfY, maxX, halfY);
	    	    gc.drawLine(halfX, 0, halfX, maxY);
 Button b = new Button(composite, SWT.PUSH); b.setText("Plot");
	    b.addListener(SWT.Selection, e-> {
	    	GC gc = new GC(canvas);
		    	    gc.drawOval(100, 200, 20, 20);
//And nothing happens!

[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 Mar 04 17:10:15 GMT 2021

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

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

Back to the top