How to paint in Component Graphics?

V

VideoProcessor

Does anyone have a solution for painting in components without overwriting
the paint-Method?

I can access a component'g Graphics-Object by

Component abc;
....
Graphics g = abc.getGraphics();



Then I'm able to paint in it:

g.drawRect(10, 10, 20, 20);



.... and paint it in the component:

abc.paint(g);



The problem to solve is that after updating the component, the rect is not
visible, because it's not in the component graphics. Is there any way to do
this without overwriting the component? Or a way to send a notice that the
component graphic was updated so that I can repaint the rect immediately?
 
A

Andrei Kouznetsov

Does anyone have a solution for painting in components without overwriting
the paint-Method?

I can access a component'g Graphics-Object by

Component abc;
...
Graphics g = abc.getGraphics();



Then I'm able to paint in it:

g.drawRect(10, 10, 20, 20);



... and paint it in the component:

abc.paint(g);



The problem to solve is that after updating the component, the rect is not
visible, because it's not in the component graphics. Is there any way to do
this without overwriting the component? Or a way to send a notice that the
component graphic was updated so that I can repaint the rect immediately?

why you don't want to overwrite paint?
 
V

VideoProcessor

why you don't want to overwrite paint?

Beacause I can't access the code ... ;-)
It's the visual component of a jmf video player and I have to mark some
regions in it.
Maybe any other idea for doing this?
 
A

Andrew Thompson

It's the visual component of a jmf video player and I have to mark some
regions in it.

Get the graphics of the video player and render them to
the Graphics of a BufferedImage, paint your rectangle on
same, paint BufferedImage ( quickly ;-).
 
A

Andrei Kouznetsov

Beacause I can't access the code ... ;-)
It's the visual component of a jmf video player and I have to mark some
regions in it.
Maybe any other idea for doing this?

put your video player into some component with glassPane (JFrame for
example) and paint whatever you need on glassPane.
 
V

VideoProcessor

put your video player into some component with glassPane (JFrame for
example) and paint whatever you need on glassPane.

I tried to, but it seems as if the glassPane is still under the visual
component of the player.
 
A

Andrei Kouznetsov

I tried to, but it seems as if the glassPane is still under the visual
component of the player.

this say us that the player is a heavyweight component!
and you have a big problem.

However I yet don't understand why you cant extend your player and write
something like this:
class MyPlayer extends VideoPlayer {

public void paint(Graphics g) {
super.paint(g);
//draw here whatever you want
}

If player is final class then use reflection to make it not final and
create/compile MyPlayer on the fly at run time.
 
A

Andrei Kouznetsov

put your video player into some component with glassPane (JFrame for
I tried to, but it seems as if the glassPane is still under the visual
component of the player.

dont use glassPane, use one Component for every your drawing and place it
over your player!
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top