The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Painting swing components to an arbitrary position?

Hi, first post, but I'll try to repay the favor by hanging around and helping others if someone solves this problem for me

I'm working on a project for a conferenceware program and I now need to know how to draw a JComponent to any spot on the screen. My first lead from Google was the CellRendererPane, which worked fine.... If I had of wanted to draw a rectangle. The paintComponent method didn't do anything, much less tell me if something was wrong. So I went searching again and stumbled across SwingUtilities.paintComponent. This one told me something was wrong, but gave me nothing to fix it. It threw a NullPointerException about a CellRendererPane, which left me wondering if it would have worked anyway.

tl;dr: Anyone have some sample code I can have a look at? This may need to include some initialisation code that would be easy to miss (at this stage I'm just constructing the components and chucking it through the methods). Any help at all would be appreciated, as I really don't want to have to write this thing from scratch