-5

My friend and I are working together to write a Java program, and I am taking on the task of designing the GUI. Our GUI requires a background image for the JFrame, and the image needs to be able to change based on the user's actions. I have placed the images that I want to use as the background in the project as a resource, and I would like to ask for help finding the resource path, and setting the resource path as the background image in the JFrame.

I am using the Swing GUI Builder for NetBeans to design the GUI. Can someone please offer me some help? I have no experience with GUIs, and my friend has little experience with basic Java coding, so we are assigning parts based on our knowledge.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
PWF
  • 115
  • 1
  • 4
  • 15
  • 1
    You asksed like five questions. You need to show what you have done and the step you are having trouble with. – djechlin May 24 '13 at 22:01

1 Answers1

3
  1. If you don't want to resize the images (as the frame changes), you could simply set the frames layout to BorderLayout and use a JLabel to display the images. Otherwise you will need to construct a custom component (using something like JPanel) and render the image yourself
  2. Looking up embedded resources is a simple process of using something like getClass().getResource(...), where the parameter is the path to the resource, where the root is the top level source folder in your project.

Take a look at...

Community
  • 1
  • 1
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • 1
    See also the [Q&A](http://stackoverflow.com/a/9866659/230513) cited in the [info](http://stackoverflow.com/tags/embedded-resource/info) for the [tag:embedded-resource] tag. – trashgod May 24 '13 at 23:08
  • @trashgod I was talking about being able to change the image that goes on the background, but centering the image is important as well for what I am trying to do. – PWF May 24 '13 at 23:47
  • @PWF: I wanted to get the handy [tag: embedded-resource] material on the record. In your [sscce](http://sscce.org/), access posted images via `URL`, as shown [here](http://stackoverflow.com/a/10862262/230513), or use synthetic images as shown [here](http://stackoverflow.com/a/15982915/230513). – trashgod May 25 '13 at 00:03
  • Changing the image comes down to how you display it – MadProgrammer May 25 '13 at 00:03