Skip to main content



      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 15:38
Eclipse UserFriend
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 01:07] by Moderator

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


Current Time: Sat Jul 05 18:44:06 EDT 2025

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

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

Back to the top