Gradient paint or image as a background in JPanel.

A

Aaron Fude

How to do it?

I found a few ways to do it on the web, but there's gotta be one de-
facto-standard way of doing it. What would that be?

Thanks,

Aaron
 
A

Andrew Thompson

How to do it?

I found a few ways to do it on the web,

Why? It is not exactly common that a program needs a
gradient or image BG to a panel.
...but there's gotta be one de-
facto-standard way of doing it. What would that be?

Why not use one of the techniques you found, and thereby
make it (by force of numbers) one step closer to being a
'de-facto standard'?
 
A

Aaron Fude

Why?  It is not exactly common that a program needs a
gradient or image BG to a panel.


Why not use one of the techniques you found, and thereby
make it (by force of numbers) one step closer to being a
'de-facto standard'?

All of those techniques seemed ad-hoc. I would like to learn the right
place to put the code? Is it "paint" or "paintComponent", or?
 
M

Mayeul

Aaron Fude a écrit :
All of those techniques seemed ad-hoc. I would like to learn the right
place to put the code? Is it "paint" or "paintComponent", or?

I think the javadoc is rather clear that a JComponent's background
should be drawn in its paintComponent() method and that paint() should
be left alone for this.

It probably should be drawn first thing too, not touch the border insets
if there are some, and honor isOpaque() (that is to say, do fill the
background with opaque paint if isOpaque() is true.)

As for how to actually draw the thing, it seems you already found
working examples.
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top