paint in canvas

T

tratrillo

sorry for the probably dumb question,
but I'm new to java: I have a small example
that draws a rect in a paint method of
the canvas.

based on an event I redraw the rect with a
different color (with a call to fillRect).

The problem is that if I put the window in
background and then get it in forground, I
see the change, otherwise nothing appens!
Seem I'm missing a update call.

By the way, if I call the sequence
canvas.setVisible(false);
canvas.setVisible(true);
it works, but I do not want to redraw all the
canvas, just the rect, to avoid flickering.

thanks
G.
 
R

Roedy Green

it works, but I do not want to redraw all the
canvas, just the rect, to avoid flickering.

I don't see how anyone will be able diagnose problems without seeing
the code.

to repaint just a small part of the drawing, use a repaint with a
clipregion.
 
T

Thomas Hawtin

The problem is that if I put the window in
background and then get it in forground, I
see the change, otherwise nothing appens!
Seem I'm missing a update call.

And if you drag a window over the top, only the are that has been
covered is redrawn?
By the way, if I call the sequence
canvas.setVisible(false);
canvas.setVisible(true);
it works, but I do not want to redraw all the
canvas, just the rect, to avoid flickering.

You need to tell the UI toolkit that the rectangle is 'damaged'. Call
Component.repaint with the bounds of the rectangle in the component's
coordinates.

http://download.java.net/jdk6/docs/api/java/awt/Component.html#repaint(int,
int, int, int)

Tom Hawtin
 
G

Giorgio Schiavon

Hi,
I'm here again: the repaint works correctly
using jdk, but using kaffe, what I get is...
only the repaint og the modified rectangle :-(
That is the window is cleared, and then,
only the rect indicated in repaint is repainted.

Any idea why kaffe clear all the windows?

thanks
G.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top