The Artima Developer Community
Sponsored Link

Java Answers Forum
setting a background color for applet

1 reply on 1 page. Most recent reply: Mar 14, 2002 8:55 AM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Aleksandr Kravets

Posts: 1
Nickname: webtekie
Registered: Mar, 2002

setting a background color for applet Posted: Mar 14, 2002 8:12 AM
Reply to this message Reply
Advertisement
Hi,

I am trying to set-up a JPanel with GridBagLayout, and setting a background image for that JPanel. For now I have accomplished setting up the JPanel and putting my components in it. However, I am not sure how to attach a background image to that panel, does anybody know how to do it?

thanks,
webtekie


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: setting a background color for applet Posted: Mar 14, 2002 8:55 AM
Reply to this message Reply
You can draw your image then set xor mode and draw over it. The image will appear as a background.

in the JPanel's paint method:

setXORMode(Color c1)
where c1 is the XOR alternation color

public void paint(Graphics g){

g.drawImage(Image img, int x,int y,Color bgcolor, ImageObserver observer);

setXORMode(Color yournextcolor);

g.draw...... draw the rest
............
}
}

Flat View: This topic has 1 reply on 1 page
Topic: Arraylist Previous Topic   Next Topic Topic: Windows XP and Windows 64-bit OS Vs JAVA

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use