By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 1,005 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

Painting components on Panel Picture ?/?

P: 18
I have been searching all over the sites, but i couldn't manage to get button or any other component on a image panel. There are some codes that says while painting the picture you can show components. Basically they are overriding the paint method of the panel. But i need to make my frame background image while not having the diffuculties of overriding the paint method of panel because i have many components . Netbeans offers me to change background color , but i need to change the background image, So, is there any concrete solution to that problem . Thanks in advance.
Dec 18 '09 #1

✓ answered by pbrockway2

Override paintComponent() in the panel to draw the background. This has nothing to do with whether you have child components or how many you have. Basically you have to paint the background somewhere, and paintComponent() is the place.

See A closer look at the painting mechanism in Sun's Tutorial. (The Tutorial, by the way, is a better source of factually accurate material than "some codes" on teh internet, or random responses - including this one - from forums.)

As far as the child components are concerned, just add them. They get painted along with the background as explained in the link above.

[Edit] I have no clue about how this is done in NB. It's (yet another) case of the GUI builder facilitating the use, but obscuring the understanding of the technology. Perhaps you could put the IDE aside for a bit.

Share this Question
Share on Google+
1 Reply


Expert 100+
P: 151
Override paintComponent() in the panel to draw the background. This has nothing to do with whether you have child components or how many you have. Basically you have to paint the background somewhere, and paintComponent() is the place.

See A closer look at the painting mechanism in Sun's Tutorial. (The Tutorial, by the way, is a better source of factually accurate material than "some codes" on teh internet, or random responses - including this one - from forums.)

As far as the child components are concerned, just add them. They get painted along with the background as explained in the link above.

[Edit] I have no clue about how this is done in NB. It's (yet another) case of the GUI builder facilitating the use, but obscuring the understanding of the technology. Perhaps you could put the IDE aside for a bit.
Dec 18 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.