How do you change the image in a JPanel?

Hey! (firstly, i need to use image on a JPanel, label&icon not an option).
I've made my JPanel class
    public class DrawingPanel extends JPanel {
        Image img;
        DrawingPanel() {
            Image img = Toolkit.getDefaultToolkit().getImage("13.jpg"); //default image at startup
        public void paintComponent (Graphics g) {
            super.paintComponent (g);
            // Use the image width & height to find the starting point
            int imgX = getSize ().width/2 - img.getWidth (this);
            int imgY = getSize ().height/2 - img.getHeight (this);
            //Draw image centered in the middle of the panel   
            g.drawImage (img, 0, 0, this);
        } // paintComponent
    } // DrawingPanelAnd I've made my instance of it and added it to the Frame:
    DrawingPanel imagePanel = new DrawingPanel();Now, I need to change the image on the JPanel according to the user's input. I have the string of the location of the new image. How do I update the JPanel to display this new image? Any help greatly appreciated!!

Well... You could just add a method in your class which sets the image according to the new image name you provided. Something like this:
    public class DrawingPanel extends JPanel {
        Image img;
        DrawingPanel() {
            img = Toolkit.getDefaultToolkit().getImage("13.jpg"); //default image at startup
        public void setImage(String imageName) {
                img = Toolkit.getDefaultToolkit().getImage(imageName); //Loading the desired image
        public void paintComponent (Graphics g) {
            super.paintComponent (g);
            // Use the image width & height to find the starting point
            int imgX = getSize ().width/2 - img.getWidth (this);
            int imgY = getSize ().height/2 - img.getHeight (this);
            //Draw image centered in the middle of the panel   
            g.drawImage (img, 0, 0, this);
        } // paintComponent
    } // DrawingPanel

Similar Messages

  • When you drag a link onto your desktop, how do you change the image for the shortcut?

    When you drag a link onto your desktop, how do you change the image for the shortcut?

    Select it, hit command-i (or choose File -> Get Info), select the icon in the info window and paste something else there.

  • How do you change the image size and resolution in photoshop everytime I change the width the height changes my measurements will not stay

    Can someone assist me with changing image size and resolution.  each time I change the width the height changes and vice/versa?

    There's a chain link between width and height. The point is to keep the aspect ratio the same, otherwise your picture would get stretched.
    You click on the chain-link to shut that off and you can adjust width and height separately.
    Also could you give us your version of Photoshop, what OS you are running it on (Windows 7 for example) and what exactly you want to do with your document?
    Resolution is the print term for how many pixels will be printed on an inch of paper. It doesn't apply if your image is intended for screen viewing.
    Gene

  • How do you change the artwork in the new itunes? it won't let me delete it

    how do you change the album artwork in the new iTunes? it won't let me delete the old artwork even when I highlight it

    The new iTunes 12 Get Info dialog lacks right-click context menus (at least for now) but it still accepts most standard keyboard shortcuts and drag & drop actions.
    Delete Artwork
    On the artwork tab of Get Into, tap the image in question, use Backspace or Ctrl+X. Delete doesn't work.
    Or, tap the image at the top left of Get Info, this time use Backspace or Delete, it is Ctrl+X that doesn't work.
    Add Artwork
    Select artwork, press Ctrl+C to copy, tap the centre of the Artwork tab, press Ctrl+V to paste.
    Or, select artwork, press Ctrl+C to copy, tap the small image area at the top left, press Ctrl+V to paste.
    Or, you can drag & drop to, or sometimes from, the same locations.
    You can also copy artwork from the Get Info dialog to Windows Explorer with the keyboard shortcuts.
    If the source image is on a web page right-click and use Copy Image rather than copy. (With Chrome I get a one pixel wraparound so tend to go for a temporary local copy anyway - not sure whose bug this is, but it isn't new.)
    If you have multiple images embedded drag the one you want to be the primary artwork to the leftmost position.
    Replace/Remove All Artwork
    The top left image box can be used to add or delete art from multiple tracks. In either case all existing artwork in all tracks is replaced/removed.
    Old Style Get Info Dialog
    Select some items, right-click, hold down shift, then click Get Info from the context menu. (Use alt/option on a Mac)
    tt2

  • How do you change the Print Products Store from USA to UK like you can do in IPhoto?

    How do you change the Print Products Store from USA to UK like you can do in IPhoto?

    Please keep in mind that Aperture is not an enhanced iPhoto, it is a different application with a different philosophy and a different intended audience. If you approach it with that in mind you will have a lot less frustration as you learn Aperture.
    Aperture adds a layer of complexity that is not needed by many.  iPhoto is a very powerful application and fits the needs of many amateur photographers.
    As for your original issue, as I said I am surprised that iPhoto allows you do switch countries like that and am not surprised that Aperture doesn't. If this is something you really need to do working in Aperture but using iPhoto to order the prints is a good work around and will not be all that difficult to do once you get the hang of it.
    As for your new question, the books in iPhoto and Aperture are different enough that the code that created the book in iPhoto wouldn't work in Aperture. What happens when you import an iPhoto library into Aperture is that the images in the book are combined into an album in Aperture with the same name as the iPhoto book. You will need to re-create the book in Aperture uaing the images in this album.
    Hope this helps, post back if you have anymore questions.
    regards

  • How do I change the image size by pixels

    In the older version of photoshop you could change the image size and change it by pixels independently. With photoshopcc if I change the width the height changes. How do you change the 2 values independently to get the desired size?

    You'll want to use the Camera icon to upload your screenshot images when you reply.
    But jml007 has the answer I think you want. Change the units from inches to pixels and click on the chain link to turn it off and enter your W H values independently.
    Mark his answer as correct if this solves your issue.
    Gene

  • How do I change the image title when it is uploaded from iphoto to iweb. At the moment the image title is /shapeimage_1.png and I would like to put in something more relevant than just shapeimage?

    How do I change the image title when it is uploaded from iphoto to iweb. At the moment the image title is /shapeimage_2.png and I would like to put in something more relevant than just shapeimage_2?

    When you drag images from iPhoto to iWeb, iWeb retains the original filename.
    When you use a mask, iWeb creates a png file with the shapeimage name.
    So do not use a mask and crop your images before dropping them on the iWeb canvas.
    When you use an irregularly shaped mask, then png files are created. They have to be png because of the transparency of the shape.
    You can use a 3rd party application to create the png images yourself, and give them a proper name.
    Or use the published png files, rename them and drop them back onto the iWeb canvas, while first removing the previous images.

  • How do you change the dpi settings in iPhoto

    How do you change the dpi settings in iPhoto

    Short answer: the dpi is set when you decide what size you're printing at.
    Long Answer: Dpi means nothing in the digital world of your computer. There are no "inches" to have "dots per..." Size is measured in pixels. That's the same on your camera. It doesn't take 10 x 8 or 6 x 4 shots. It takes shots measured in megapixels. For instance 4,000 x 3,000 is a 12 megapixel camera.
    Using that example, that shot from that camera has 12 million pixels. So that's how many "Dots" there are. To decide the ratio of dots per inch, you now need to decide the "inches" part. And that's printing.  Print at 10 x 8 and the dpi will be 4,000/10 or about 400 dpi. At 6 x 4 then it's 4,000/6 or 660 dpi. Work the other way: Print at 300 dpi and the resulting image will be about 13 inches on the longer side.
    So, your photo as a fixed number of pixels. Changing the dimensions of the print will vary the dpi, changing the dpi will vary the dimensions of the print.
    For more see http://www.rideau-info.com/photos/mythdpi.html
    Regards
    TD

  • How can i change the image in portal logon screen

    hi guys
    pls tel me
    how can i change the image in portal logon screen
    thanks
    regards
    kamal

    Hi
    Download the par file com.sap.portal.runtime.logon.par.bak from
    Go to System Administration -- Support -- Portal Runtime -- Browse Deployment.
    The path should ROOT/WEB-INF/deployment/pcd. Now download that file into local system.
    Create a Par project and make necessary chenages ..i.e
    Open the downloaded par file with WinZip and inside the lib folder three jar files named com.sap.
    portal.runtime.logon_api.jar, com.sap.portal.runtime.logon_core.jar and umelogonbase.jar will be there. Copy those files in the folder u2018libu2019 in par project.
    Now change a branding Image...i.e
    Replace the branding-image. jpg with your company branding image in the same name.
    Once modifications are done,then create a par project and upload the par file into portal.
    Go to the path System Administration -- Support -- Support Desk -- Portal Runtime -- Administration console.
    then browse the file and click on upload.
    Connect to server where the Portal WebAS is running and go to:
    (drive):\usr\sap\<system id>\<system instance>\j2ee\cluster\server0\apps\sap.com\com.sap.security.core.admin\servlet_jsp\logon\root\layout.
    There you will find the images used on logon screen, you can replace them for your
    company images, please take care with the width of the images, as usual, to make this
    change effective, you must restart the whole WebAS.
    Regards,
    Raju

  • How do I change the image used on an movie project icon? iMovie seems to select an image at random from the images I imported.

    How do I change the image used on an movie project icon?
    iMovie seems to select an image at random from the images I imported.

    Not sure I understand how to use what you have posted. Here's what my init() looks like:
    public void init()
    setLayout(new BorderLayout());
    p=new Panel();
    p.setLayout(new GridLayout(1,1));
    callnowButtonURL = getURL(callnowButtonFilename);
    if (callnowButtonURL != null)
    callIcon = new ImageIcon(callnowButtonURL,"call");
    endcallButtonURL = getURL(endcallButtonFilename);
    if (endcallButtonURL != null)
    endIcon = new ImageIcon(endcallButtonURL);
    b=new JButton(callIcon);
    b.setBorder(new EmptyBorder(0,0,0,0));
    b.setBorderPainted(false);
    b.addActionListener(this);
    p.add(b);
    add(p,"Center");
    Now the ActionListener is basically:
    public void actionPerformed(ActionEvent e)
    if (mybool == false)
    <Perform actions here set mybool to true>
    Change JButton b to use EndIcon
    else
    <Perform actions here set mybool to false>
    Change JButton b to use CallIcon
    Can you clarify how to perform the action I require? You can have a couple of Dukes if you can help me sort this out.

  • How Do I Change The Image Used For The Power Up Screen?

    Windows 8.1 Pro with all patches.
    How do I change the image that is shown when you power up a PC?
    Note: This is not the Start Screen background or the Lock Screen background or the Desk Top background.
    http://www.saberman.com

    Unfortunately, the suggested solution in that thread does not work and the thread appears to be closed to replies.  That is, even though I am logged in the Reply|Quote|Mark as answer|Report as abuse items are missing.
    The suggested solution is:
    First, I found I had "img100.png" in  C:\Windows\Web\Screen  and
    C:\Windows\WinSxS\x86_microsoft-windows-themeui-client_31bf3856ad364e35_6.2.9200.16384_none_69ee3fa2269e545e
    1. Belonging to the Administrators Group, I replaced file Owner TrustedInstaller with my Username on both "img100.png" files
    2. After resizing the image I wanted to see on the Login screen to the resolution of "img100.png" file,
    I copied and pasted it to both "img100.png" files keeping this way the format (extension) and resolution of the original "img100.png" file,
    which I permanently deleted.
    However, I have not been able to replace the img100.pgn in C:\Windows\Web\Screen even after taking ownership of it and setting the permissions for my userid to All.  I edit it with mspaint and then try to save it. The save starts that then says the
    save was interrupted.
    The appears to be some additional protection besides the standard acls.
    http://www.saberman.com

  • HT5312 How do you change the email address used to send security answers?

    How do you change the email used to send the security answers you have forgotten? I have changed the alternative email adress in Name, ID and Email Addresses but this does not change the email address in the Password and Security section.

    Jus what do you want to accomplish? The Apple ID email address is used for variosu thing onthe iPod like:
    - For purchasing media. Srrings.iTunes and App stores. Sing out and sign into anoterh account
    - Settings>iCLoudl for iCloud account
    - Settings>FaceRome for Apple ID and where You can Be Reached At email address
    - Settings>Messages for Send And Receive email address.
    - Maybe for Game Center

  • Same question for the "2 iPhones in one account".....How do I change the name.  My iPhone is showing my wife's iPhone name when I am syncing it.  Why is that?  I know about using one iTunes account....But how do you change the name w/o erasing your data?

    Hi....How do you change the name?  When I sync my iPhone, it shows my wife's name on it?

    Unfortunately it is not doing it....
    Let me give more details..We have 3 iPods and 2 iPhone4....I recently purchased the iPhone4 and when we connected it..It was already reading my wife's iPhone4..We went to the Apple Store at the Grove today and was told to de-authorize the system and connect my iPhone4 back and I should be able to change the name.
    Nothing happened..Right now, I clicked on RESTORE settings...and it is uploading a new iPhone update. 

  • HT204053 I used one Apple ID to set up iCloud after iOS 6 was downloaded to my iPhone, now I want to change the Apple ID for iCloud on my iPhone but I'm unable to. How do you change the ID after it's been set up?

    I used one Apple ID to set up iCloud after iOS 6 was downloaded to my iPhone, now I want to change the Apple ID for iCloud on my iPhone but I'm unable to. How do you change the ID after it's been set up?

    See https://discussions.apple.com/message/19218571#19218571.

  • How do you change the Apple ID for my iPhone 4?

    How do you change the Apple ID for my iPhone 4. I am able to access my iTunes account using my new ID and password on my computer; however, my iphone has a different Apple ID and I do not have cannot access iTunes on this phone. 

    Also, if you have iCloud, you will probably also want to change the iCloud account on the phone to be yours:
    Settings>iCloud - if Account is not yours, go to the bottom and Delete Account. Then sign back on with your iCloud account info.
    Cheers,
    GB

Maybe you are looking for

  • Creative Zen freezing in spite of following all fi

    I have had my Zen Sleek for 8 months with no problems at all. A few hours ago it froze in the Creative start-up screen. I rebooted into recovery mode and tried to run "Clean Up". It has been displaying the "scan disk" message for about an hour now an

  • Cannot install J2SE on debian

    Hi All, I have a Debian box, and tried installing J2SDK-1_4_2 on it, but in vain. I downloaded the j2sdk-1_4_2_09-linux-i585.bin and followed the installation instruction but when i issue ./j2sdk-1_4_2_09-linux-i586.bin I get an error stating bash: .

  • Safari not being able to open...?

    Starting yesterday, whenever I attempt to open safari, it will simply bounce on the dock and then I will get a "The application Safari quit unexpectedly" notice before a window even pops up. I have a copy of one of the Problem Reports in hopes that s

  • Limited downloading, forced to reconnect to wifi

    so i have an issue that has just started.  when i connect to my wifi and i begin to browse with google chrome or safari, i'll from page to page whether it be espn.go.com or facebook or what not before my imac stops downloading information.  if i go t

  • Multiple attachments (TIF-files) in Emails

    hi all, I'm trying to send an eMail with multiple attachments (TIF-files) with the function SO_NEW_DOCUMENT_ATT_SEND_API1. The eMail with the attachments arrives well. The problem is, when opening the attachments all look the same as the 1. attachmen