How do you set an image into the background of a JPanel or JFrame?

How do you set an image into the background of a JPanel or JFrame?

Something like this, Ive thrown in an ImageIcon on a
button too for good measure.
import java.awt.*;
import javax.swing.*;
public class JFrameImage extends JFrame {
public JFrameImage() {
Container c    = getContentPane();
JPanel panel = new JPanel(){
             public void paintComponent(Graphics g)     {
ImageIcon img = new
= new ImageIcon("background.jpg");
                  g.drawImage(img.getImage(), 0, 0, null);
                  super.paintComponent(g);
        panel.setOpaque(false);
ImageIcon icon = new ImageIcon("onButton.jpg");
JButton button = new JButton(icon);
panel.add(button);
c.add(panel);
public static void main(String[] args) {
JFrameImage frame = new JFrameImage();
frame.setSize(200,200);
frame.setVisible(true);
Going totally fancy pants
ImageIcon bigImage = new ImageIcon(bgImage.getImage().getScaledInstance(getWidth(), getHeight(),Image.SCALE_REPLICATE));
g.drawImage(bigImage.getImage(), 0, 0, this); Will scale the image to the size of the panel
whereas
for (int y = 0; y  < getHeight(); y = y + image.getHeight(null))
for (int x = 0; x< getWidth(); x = x + image.getWidth(null))
g.drawImage(image, x, y, this); Will give a tiled effect
Try tiling with an animated gif and bring your processor to a standstill.

Similar Messages

  • How do you set a image in the background of a JTextfield?

    How do you set a image in the background of a JTextfield? Any ideas?

    You can't thats why it is called textfield!!!
    Take a look at JScrollPane API for this

  • How do you paste an image into a rectangular marqee forcing it to resize into the marqee?

    How do you paste an image into a rectangular marqee forcing it to resize into the marqee?

    Not sure this would address your issue, but the Crop Tool works that way: set the width and height, plus resolution, and Crop does everything. You could then paste the result into another file if that completes your process.

  • How do you open an image on the iPad, via Photo Stream, into PS Touch?

    To anyone using an Apple iPad w/ PS Touch.  How do you open an image on the iPad, via Photo Stream, into PS Touch?

    You need to start from PS Touch for this.
    There's two ways either direct in the gallery with the +image icon.
    Or you create a document and use the +image icon in the document view.
    thanks,
    Ignacio

  • How do you add an image in the signature

    Hi,
    How do you add an image to the signature area.
    The Insert/edit image is not available when in My Settings | Personnel Info | Signature
    Regards
    Ray Farmer

    You need to link the image.  See the example for the Canada flag below.
    <img src="http://forums.ni.com/ni/attachments/ni/130/6908/1/Canada-small.PNG" border=0>
    Replace with the image you like.  This goes into the signature box within the profile tab of the personal settings.
    RayR

  • How do you show thumbnail images for the contacts?

    How do you show thumbnail images for the contacts on the iPod?
    -Thank You

    In another thread I posted a suggestion to try when the iPhoto app in the Application folder will not work:
    after upgrading the OS, iPhotos (and Aperture for that matter) should still be in the Applications folder...
    And running well in 10.10.3.
    If it stops running in a next "update" do not throw it away: most apps will continue running as follows:
    In the Applications folder "rightclick" (CTL+click) the iPhoto app, then "show package contents", then click the MacOs folder open: you see the real app (dark grey), rightclick this and choose "make alias", an alias is made, move this alias to the Applications folder and use it to run iPhoto.
    Same for Aperture.
    In older OS this survived several upgrades....
    Lex

  • How do you load artworks automatically into the indeisgn CS3

    Hi All,
    How do you load artworks automatically into the indeisgn CS3. Is it through a script or any other way.
    Thanks
    Devakanth

    "artworks" is a bit vague...can you expand?
    File > Place is the usual way, but there are times when cut and paste is fine or better.

  • For the ipod on my phone, each song has a different volume. How do you set it so all the songs have the same volume?

    For the ipod on my phone, each song has a different volume. How do you set it so all the songs have the same volume?

    Copy everything from your old computer, or your backup copy of your old computer, to your new one.

  • How do you set up iCloud on the iPod touch if it says too many apple accounts have been signed onto the device

    How do you set up iCloud on the iPod touch if it says too many apple accounts have been signed onto the device.

    Welcome to the Apple community.
    Unfortunately you will need to create your Apple ID (account) on another mobile device or a Mac computer. Once three iCloud accounts have been created on an iOS device, it doesn't matter what you do to that device, no further accounts can be created on it.

  • HT2513 How do you set up reminders if the New Reminders tab is not located under file?

    How do you set up reminders if the New Reminders tab is not located under file? This is a iCal question.

    You set up reminders in the Reminders app.

  • How do you set a default on the Mac that automatically starts a sentence with a capital letter after a full stop? Thanks guys....

    How do you set a default on the Mac that automatically starts a sentence with a capital letter after a full stop? Thanks guys....

    I use SpellCatcher.  
    17" 2.2GHz i7 Quad-Core MacBook Pro  8G RAM  750G HD + OCZ Vertex 3 SSD Boot HD 

  • In the new Pages, how does one send an image to the background (and make it selectable)?

    How does one send an image to the background in the new Pages and how does one make it selectable?

    Also why don't TEXT to Speech short cuts established in system preferences work in the new Pages?
    I am confused (and not completely happy)

  • HT4528 How do you close programs running in the background after you update to the ios7?

    How do you close programs running in the background after you update to the ios7?  It no longer works to tap the button twice

    double tap the home button, and swiipe upp on the app screenshot

  • How do I Place an image into the center of an activated artboard in CC?

    I have just upgraded to CC from CS6. In CS6, I could activate an artboard (double click it in the Artboard panel) and then Place an image, which would by default go into the center of the artboard.
    With CC, it "loads" the image into the cursor which I then need to Place by clicking somewhere.
    How can I get it to either behave as it did in CS6, or customize to load it into the center when I click, such as with a modifier key?
    Thanks!

    Hi,
    With the Window > Allign panel,
    You can select the option to allign to selection or to Artboard.
    When you select "to Artboard" you schould be able to use the Allign option to get it centerred.
    See preview bellow.
    Hope this helps.

  • How can i add an image into the header

    When printing a webpage i would like to ad an image into the header? Is this possible?

    Thanks. The triangle was buried in the image. If you hadn’t told me where to look, I would never have found it!
    Michelle
    Michelle Lancto
    Jewish Endowment Foundation
    a division of the Jewish Federation of Western Massachusetts
    Phone: 413-732-9994                Fax: 413-737-4348
    <mailto:[email protected]> [email protected]
    <http://www.jefwesternmass.org/> www.jefwesternmass.org 
    <http://www.jewishwesternmass.org/> www.jewishwesternmass.org
    JEF_Logos_1101_JFWM for email LOW RES
    Confidentiality Notice
    The information contained in this message and or attachments is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material.  Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any system and destroy any copies.

Maybe you are looking for

  • Incorrect content-type found 'text/html'

    Hello, I am trying to print a BI report result from portal. I get the error message "Error while generating PDF". When I see the detail of the message, I could find the mesage "Incorrect content-type found 'text/html'" We are using web templates of B

  • Purchase Value & Qty thro' 501 mvmt type

    Dear All, where can i get the Total value of Purchased material of 1 month thro' 501 mvmvt type ? And also a report of  Vendor wise purchased qty in 1 month ? regds, CB

  • Mac Pro (2014) fan

    Mac Pro (2014) fan runs constantly

  • GINR and GRNI Clearing

    Hi All, What are the function of good invoice not received (GINR) and good received not invoice clearing (GRNI) accounts ? When will they be used and in what document so that I can find the journal entry that debited or credited them? Pls give advice

  • NsUniqueId in sun java directory server 6.3 EE

    Hello in the Directory server each user has a nsUniqueId what is the utility of such field? can be used as unique identifier by external applications? how does the directory server handles this ID? is it possible to be reused eg: creation of an user