How to repair canvas? [message #534089] |
Mon, 17 May 2010 20:35  |
Eclipse User |
|
|
|
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 #534321 is a reply to message #534313] |
Tue, 18 May 2010 12:13   |
Eclipse User |
|
|
|
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();
}
}
|
|
|
Re: How to repair canvas? [message #534394 is a reply to message #534321] |
Tue, 18 May 2010 21:15  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.05793 seconds