Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to repair canvas?
How to repair canvas? [message #534089] Tue, 18 May 2010 00:35 Go to next message
Eric Jain is currently offline Eric JainFriend
Messages: 266
Registered: July 2009
Senior Member
I have a Canvas that is partially obscured when a combo box above it is opened. After the combo box is closed, the part of the Canvas that was obscured appears blank. How can this situation be handled without having to install listeners on any control that could obscure the canvas?
Re: How to repair canvas? [message #534136 is a reply to message #534089] Tue, 18 May 2010 08:19 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
You can refresh the canvas by calling redraw and update....

but if you want to update that specific area then you need to know the exact bounds and use redraw(int x, int y, int width, int height, boolean all)

but the question is why is it not repainting itself when the combo collapses?
How are you painting the canvas??



---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: How to repair canvas? [message #534313 is a reply to message #534136] Tue, 18 May 2010 15:42 Go to previous messageGo to next message
Eric Jain is currently offline Eric JainFriend
Messages: 266
Registered: July 2009
Senior Member
vijay wrote on Tue, 18 May 2010 04:19
[...] but the question is why is it not repainting itself when the combo collapses?
How are you painting the canvas??


The canvas repaints itself after being resized or obscured by another window, but not in the case mentioned above.

Here's how the canvas is painted:

Canvas canvas = new Canvas(composite, SWT.BORDER);
canvas.addPaintListener(new PaintListener() {
  public void paintControl(PaintEvent e) {
    // draw on e.gc...
  }
});

Re: How to repair canvas? [message #534321 is a reply to message #534313] Tue, 18 May 2010 16:13 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
How come this snippet works

or can you reproduce it in this

package org.eclipse.gef.examples.shapes;

//Send questions, comments, bug reports, etc. to the authors:

//Rob Warner (rwarner@interspatial.com)
//Robert Harris (rbrt_harris@yahoo.com)

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

/**
 * This class demonstrates a Canvas
 */
public class SimpleCanvas {
  /**
   * Runs the application
   */
  public void run() {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Canvas Example");
    createContents(shell);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }

  /**
   * Creates the main window's contents
   * 
   * @param shell the main window
   */
  private void createContents(Shell shell) {
    shell.setLayout(new GridLayout());

    

    // Create a button on the canvas
    Combo combo = new Combo(shell, SWT.PUSH);
    //combo.setBounds(10, 10, 300, 40);
    combo.setItems(new String[]{"ONE","TWO","FOUR","FIVE"});
    combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
 // Create a canvas
    Canvas canvas = new Canvas(shell, SWT.BORDER);
    canvas.setLayoutData(new GridData(GridData.FILL_BOTH));
    // Create a paint handler for the canvas
    canvas.addPaintListener(new PaintListener() {
      public void paintControl(PaintEvent e) {
        // Do some drawing
        Rectangle rect = ((Canvas) e.widget).getClientArea();
        e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_RED));
        e.gc.fillRectangle(rect);
      }
    });
  }

  /**
   * The application entry point
   * 
   * @param args the command line arguments
   */
  public static void main(String[] args) {
    new SimpleCanvas().run();
  }
}


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: How to repair canvas? [message #534394 is a reply to message #534321] Wed, 19 May 2010 01:15 Go to previous message
Eric Jain is currently offline Eric JainFriend
Messages: 266
Registered: July 2009
Senior Member
Issue solved: I was using gc.getClipping() rather than canvas.getClientArea() when calculating how to place lines etc. When drawing the canvas first (or switching windows) the clipping equals the client area; but this is not the case when repairing the damage done after being partially overlapped.
Previous Topic:Scrollbar not appearing at startup
Next Topic:SWT.Show not called for child widgets?
Goto Forum:
  


Current Time: Fri Aug 23 02:28:37 GMT 2019

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

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

Back to the top