Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Who can tell me how make an image background for jframe


Who can tell me how make an image background for jframe
by using netbeans?

using netbeans not other!

Your rating: None

Background

Hi,

you can overwrite the paintComponent-method of the JFrame:

_background = new ImageIcon(getClass().getClassLoader().getResource("background.jpg"));

...

protected void paintComponent(final Graphics g) {
  super.paintComponent(g);

  int alignmentX = getWidth() - _background.getImage().getWidth(this);
  int alignmentY = getHeight() - _background.getImage().getHeight(this);
  g.drawImage(_background.getImage(), alignmentX, alignmentY, this);
}

Bye,
Torsten

reply to Torsten

Thank you very much!
I solved this problem successfully!

Torsten

Nope, Torsten did! You just implemented it :)

To be honest ...

I also didn't solve it by myself but found it by the help of google ;-).

I think this works to though it has been awhile

ImageIcon Img = new ImageIcon(<path to icon>);
JFrame Frame;
Frame.setBackground(Img);

I think that is how we used to do it when we did guis in class. Hope I helped. (Lot lighter than the last suggestion.)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <p> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br /> <br> <strike>
  • Lines and paragraphs break automatically.
  • Use <!--pagebreak--> to create page breaks.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
Just checking to see if you're an actual person rather than a spammer. Sorry for the inconvenience.