Re: Change the image of the image Background panel

Hi guys,
I m wondering how can i change the background of the image I had set earlier on as the background of the JPanel using the overriding of paintComponent() method.
What i need to do is to create a swing component with a changing image background abilities.. can anyone help me with it.. its urgent.. thanks!!!

Hi.
Please see code below. I hope it help you.
Change the image name at the constructor of MainFrame.java and put that image to folder with class files.
MainFrame.java:
import javax.swing.*;
public class MainFrame extends JFrame {
  public MainFrame () {
    ChangeBGImage panel = new ChangeBGImage();
    panel.setImage("ukr.jpg");
    getContentPane().add(panel);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  public static void main (String[] args) {
    MainFrame frame = new MainFrame();
    frame.setSize(400, 300);
    frame.setVisible(true);
}ChangeBGImage.java:
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
public class ChangeBGImage extends JPanel {
  Image image;
  public ChangeBGImage (Image image) {
    this.image = image;
  public ChangeBGImage () {
    image = null;
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (image != null) {
      Rectangle rectFull = new Rectangle(0, 0, getSize().width, getSize().height);
      Graphics2D g2d = (Graphics2D)g;
      BufferedImage buffImg = new BufferedImage(image.getWidth(this), image.getHeight(this), BufferedImage.TYPE_INT_RGB);
      Graphics2D g2d2 = buffImg.createGraphics();
      g2d2.drawImage(image, 0, 0, this);
      TexturePaint imagePaint = new TexturePaint(buffImg, new Rectangle(0, 0, image.getWidth(this), image.getHeight(this)));
      g2d.setPaint(imagePaint);
      g2d.fill(rectFull);
  public void setImage(String imageURL) {
    MediaTracker mt = new MediaTracker(this);
    image = Toolkit.getDefaultToolkit().getImage(imageURL);
    mt.addImage(image, 0);
    try {
      mt.waitForID(0);
    } catch (InterruptedException ex) {
      ex.printStackTrace();
  public void setImage (Image newImage) {
    image = newImage;
Sincerely,
Victor Letunovsky
AlarIT programmer
http://www.AlarIT.com

Similar Messages

  • HT200285 I want to change my wallpaper to an image that was available before I upgraded to IOS 8.1.3 - a close-up image of long reedy  grasses with hazy light in the background. Greyish hues. Where can find the image & how do I get it back on my phone?

    I want to change my wallpaper to an image that was available
    before I upgraded to IOS 8.1.3 - a close-up image of long reedy  grasses with hazy light in the background.
    Greyish hues. Where can find the image & how do I get it back on my phone?

    I want to change my wallpaper to an image that was available
    before I upgraded to IOS 8.1.3 - a close-up image of long reedy  grasses with hazy light in the background.
    Greyish hues. Where can find the image & how do I get it back on my phone?

  • How do I change the blurred background image on the Select User Screen

    I have changed the desktop image on all of my users, as well as the screen savers.  However, when I logout of one user and the screen where you select another user comes up, there is an image on the background of this particular screen that I cannot figure out how to change.
    This is crucial because I do not want to see my crazy, abusive ex-wife every time I select a different user...even if it is a blurred image.
    This blurred out image does not appear anywhere else on any of the different user accounts as a background/desktop image.
    How do I change this background image?
    Please help.

    This seems to be a bug that goes away w/ 10.10.1
    Yosemite login screen possible bug
    "if I put my Mac in sleep mode, when I wake up it, the password request screen uses the default Yosemite wallpaper in blurred mode instead of the wallpaper I have chosen for my desktop."
    or maybe not:
    "And it still happens after the 10.10.1 update."
    This seems to work.
    "The only way I was able to fix this problem was to go Mission Control and close all extra desktops I was using except Desktop 1 (which you cannot delete if it is the last one). After deleting the extra desktops besides Desktop 1, I went into preferences and set my wallpaper. Once I complete both of these steps I returned to the login screen. The wallpaper I used for Desktop 1 was now my background for the login screen. Hope this helps."

  • How can I change the color of interactive image label box background.

    Interactive image labels are a bit overwhelming in appearance. Can I change the label background color or make it partially transparent? I have tried several things and looked this up on Lynda.com training but no info.

    don't know how much this might help but you can change some colors using the Inspector as follows:
    from the text menu you can control paragraph and character colors, from the text menu you can control the text color.
    hope this helps...

  • How to make image stay still in background while content object scrolls over and change the background image?

    I'm fairly new to muse, so i bet it is a simple explanation to this. And don't know how to explain it in a good way. But i want the same effect as on this site http://themeforest.net/item/astlavista-multipurpose-muse-template/full_screen_preview/6459 513?ref=designrazzi . The photos stand still and changes while the blue/green content box slides over. Help anyone?

    I know how I scale the image to fill the browser. The effect I'm looking for is the transition from one image to another, as in http://themeforest.net/item/astlavista-multipurpose-muse-template/full_screen_preview/6459 513?ref=designrazzi. When the green/blue box with "services" scrolls over the screen, the image change from the one with the plane, to the one with the bike.

  • How come when I copy and paste an image I opened in gimp to a background I have in gimp the color of the image changes to the color of the background?

    Ok, im on gimp. I opened a picture of the simpsons tv in one project. I cut it out and tried to move it on to another project where the background is a gradient blue. Whenever I copy the image over, the image instantly becomes the same color as the background. Help please??

    Perhaps it has a fill color of "none", and the background shows through.

  • Can this html code be changed to speed up the image load time?

    I found some html that creates a auto running slide show. I've got three images (small image sizes) but it is slow to start up when the page is first opened. http://web.me.com/phelpssculpture/Site/test.html this is the escaped code:
    <center><img id='imageholder' src='' ></img></center>
    <script type='text/javascript'>
    images = new Array();
    images.push('http://web.me.com/phelpssculpture/Docs/typewriterprpage.jpg');
    images.push('http://web.me.com/phelpssculpture/Docs/royalprpage.jpg');
    images.push('http://web.me.com/phelpssculpture/Docs/Lovetest.jpg');
    var image_index = 0;
    function rotateImage() {
    if (image_index == images.length - 1) { image_index = 0 } else { image_index++ }
    document.getElementById('imageholder').src = images[image_index];
    setInterval('rotateImage()', 5000);
    </script>
    I have a page: http://web.me.com/phelpssculpture/Site/Resume.html
    that has a rollover image (from OldToad) that has two images about the same file size and located in the same folder on my iDisk as the other slide show images but it seems to load instantly.
    this is the escaped code:
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    loadImage1 = new Image();
    loadImage1.src="http://web.me.com/phelpssculpture/Docs/typewriterprpage.jpg";
    staticImage1 = new Image();
    staticImage1.src="http://web.me.com/phelpssculpture/Docs/royalprpage.jpg";
    // End -->
    </script>
    <a href="http://web.mac.com/phelpssculpture/Site/royal.html" onmouseover="image1.src=loadImage1.src;" onmouseout="image1.src=staticImage1.src;">
    <img name="image1" src="http://web.me.com/phelpssculpture/Docs/royalprpage.jpg" border=0></a>
    Does anyone know if it's possible to improve the html of the slideshow snippet to speed up the initial load time?
    Thanks, David

    Ethmoid:
    There are seven different pages: http://web.me.com/phelpssculpture/Site/movieroyal_davidphelps.html
    Each link is directed to a different page.
    I created the basic layout on one page and then duplicated the page six times.
    the links are in one text box ( that's why they're lined up well ) and each individual word is activated as a link. I changed the background color of the forward tab to match the color of the main shape and used the send forward or send backward command to get the tabs to look right on each page.
    The only problem with the words being in a single text box is that explorer doesn't render the spacing correctly and they fall off their respective tabs. When I get time I will put each word in it's own text box ( it's not that hard to align them ) so it will render properly in explorer.
    Sincerely, David Phelps

  • How do i make a still image (photo) fit the length of the music? I record music and want to put the tracks to a video file with a still image of my business logo in the background. Any help?

    How do I make a still image (photo) fit the length of the music? I record music and want to convert the tracks to a video file with a still image of my business logo in the background. On windows movie maker you could just select "fit to music" but this program isnt as easy to figure out! Any help?

    Double-click on the still image in the project timeline to open the Inspector. In the Inspector, adjust the duration by typing in a new duration to match the length of your music. I think the limit for a still image is 10 minutes. If you need more than this, simply drag the image into the timeline again then adjust its duration. The two images will play seamlessly (no gap will be visible).
    See this iMovie Help topic:
    http://help.apple.com/imovie/#mov3a883915
    You can achieve more precision when entering durations by changing a preference in the menu item iMovie Preferences. Check (tick) the preference for Show Time As HH:MM:SS:frames. This will enable you to enter the duration of stills down to the frame level, rather than full seconds (NTSC is 30 frames per second; PAL is 25 fps). When entering times, type a colon between each time segment, such as 2:50:15, which represents 2 minutes 50 seconds and 15 frames. For 5 seconds 20 frames you would enter 5:20 and so forth.
    Note that the music will only run to the length of the video in the timeline (in your case, the still images). So, after increasing the stills duration you will need to drag the end of the music track as far as required. The stills can be dragged inwards to reduce the duration if necessary.
    John
    Message was edited by: John Cogdell - added Note

  • Generating images on the fly to use as backgrounds for components

    I am creating an application that has an input number slider with a background image. I would like to change the background image on the slider based on its position (as chosen by the user) using a partial trigger.
    I have successfully been able to do update the background images if I have these images inside of my "Web Content" folder within my JDeveloper project. Instead, I would like to be able to generate the images as needed. These images are color gradients where the start/stop of the gradient is based on the slider's thumb position (as well as other user-defined variables). Because there are many different images that could possibly be created, I am looking into generating the images at runtime rather than have hundreds of images stored somewhere.
    I am trying to generate these images using a BufferedImage that I can then write to a file. The path I am saving it at is as follows:
    FacesContext fc = FacesContext.getCurrentInstance();
    ServletContext sc = (ServletContext)fc.getExternalContext().getContext();
    String path = sc.getRealPath("/") + filename;
    I then create the file at the path and use ImageIO to write it:
    File f = new File(path);
    ImageIO.write(bi, "png", f);
    I am saving this file path in a variable in my backing bean that I then use on my ADF page to populate the background image field of the slider.
    Problem: when I run the page, my slider does not have a background image.
    Looking at the location where the file should be saved, it is actually "saving" it within a .war file which I don't think is appropriate (or possible, for that matter). Is there some way that I can save it either on the server side or the client side so that the client can see the background actually being updated using the generated image? I am almost positive that the path I listed above is incorrect - if this is the correct approach for this problem, where would be an appropriate location?
    Any pointers would be greatly appreciated. Thanks in advance for your help!

    Instead of saving the image to a file, why not use a Servlet to write the image to the Servlet's response stream. Then, you just point the background image to the Servlet.
    John

  • How do you keep the colors of an image true when you set it as a background?

    I have an image with lines in it and a black blackground. When I set it as a background :
    html {
        background: url(../Images/backgroundimage.jpg);
        background-repeat:auto;
        background-position:center top;
    the black is a couple shades lighter so when I place a <div> with an <img>that is also mainly black on top of it, the top image is much darker than the background. I have no other css tags on the div other than a margin. The only difference in the images is I saved the background from photoshop and the image in the div from illustrator but I dont think that should have effected anything. Does anybody know anything about this because I am seriously stumped.
    Thanks

    We have been here before…
    Firstly, Adobe' Photoshop has the ability to save a color profile with an image. That color profile will be consistent across all versions of Adobe software. Problem is, Adobe does not make web browsers (and that is probably a good thing).
    When you save images for websites, you need to go through the proper Photoshop or Illustrator dialog. You want to Save for Web & Other Devices. Why? because the applications will take the image out of CMYK color space (if it is in that color space) and make it RGB. They will also try to translate the colors in a sensible way. When you use this dialog, you will see various options for JPG, including ICC Profile. Turning this on or off will change how the colors get mapped, and some experimentation to get best results is a good idea.
    I have it turned off, presently.
    The image will be set up for 72 dots per inch automatically, and you can, then, resize the image to optimize it for the website you are working on. If you are trying to fill a hole for an image that is 350 pixels wide by 250 tall, don't save the image as 1125 wide by 1024 high. That will take a long time to download from your server to whatever device is displaying it. Your original image will not be changed and you can navigate your path to your defined website's images folder.
    This should help you immeasurably. I should mention that If I am trying to match a background exactly, I will tend to knock out that color from the image, save the image as a .PNG file with transparency (where that particular color is) and place the image on the background in question with the background color I am trying to match on the website.
    -Mark

  • How do you make an image a background image if the menu option is dimmed?

    I'm using the Cork Board template in a Pages layout document. I wanted to use the cork background in another page. Option dragging the cork image creates a copy in the new page. I can "Send it to back" but the Arrange->Send Object to Background command is dimmed. The problem is that "Send it to back" does not put it behind the header or footer so my page numbers are not visible.
    Oddly, if I just drag the cork image from one page to another, it remains a background object in the new page. Copying it causes it to come out of the background.
    Anybody have an idea why the Send Object to Background command is dimmed?

    In fact, my guess is that the cork.pdf object is a background object because it is a template transferred from Pages '06 to Pages '08.
    During the conversion, some properties are passed even if they aren't treated by the new version.
    If some one wish to let some of these items in the true background, as far as I know, the only available soluce is:
    create a new object from the delivered template
    unlock some items if necessary
    remove useless items
    lock back the kept item
    save the document as a template.
    Never change the background property of the kept items.
    As far as an item is a "true background" one,
    trying to move an other item to the background will leave it above the "true background object".
    Yvan KOENIG (from FRANCE mardi 9 septembre 2008 15:49:21)

  • How to change the text in your image?

    How do I change the font in my image without changing the image itself?

    When you create text in photoshop and save the resulting image in psd or tiff, the text stays live. Allowing you to edit it later on, which is why it is recommended to save to one of the two formats for archival purposes.
    If your text is live, all you have to do is doube click on the icon in the text layer, that will highlight all of the text for that layer. You can then change the properties of that text. Draging across the text will also highlight only what you want selected, and only that portion will be affected by any changes in its properties.
    If you save to a format like jpg and that is the only copy, you then have to use the selection tools to seperate the text from its background. Once the text is selected, you then need to find away to replace what was underneath, hopefully it a solid color, but only you know, since there are no screen grabs to look at.
    If the background consist of multiple colors, you may have luck using the clone tool, or healing brush, etc. to try to mimic the area around the text. If you have CS5 or CS6 you may even have luck with the content fill feature.
    All I can say is if the text is not live, its going to take time and patience to make it look good. And use this as a learning experience for both learning how to do it the hard way and to save as a psd from now on.
    Good luck.

  • How to change the color of an image....

    I have a logo that I use that has a
    white background with black lettering. I would like to use that logo sometimes with white lettering. How can I change that using PSE 7?
    I am creating postcards with a picture on the left and a color block on the right that compliments that picture on the left. I would also like to implement a gradient of some sort from the picture to the color block. Any tips on how to do that as well? I would like it to go from left to right....

    We'll use the image you posted.
    1. Use the black and white icon in your layers palette to make a pink solid color fill adjustment layer.
    Since the mask is white the entire image will be covered by the pink color.
    2. Now, we are going to hide the entire effect (pink solid color fill adjustment layer) by filling it with black. With the solid color fill layer highlighted in the layers palette, you can use the paint bucket or just invert the white mask by pressing Ctrl + I.
    Here we see that the entire pink solid color fill layer is hidden. We are now looking at your background layer.
    We are going to use a different gradient this time and make it easier to understand. I think I used linear last time. I think it will be easier to understand going this route for this particular situation.
    3. Set your foreground color chip to white then select the gradient tool. With the gradient tool selected, open the gradient editor and select the white to transparent preset. (To open gradient editor, double click the gradient window in your options bar.
    Above is what you need to look for in the options bar to double click to gain access to the gradient editor.
    The second preset should be foreground to transparent. If white to transparent isn't available, you need to change your tool box's foreground color to white as the gradient's foreground color will be whatever is selected as the foreground color in the tool box.
    4. Here is a screen shot of my gradient tool settings that I used.
    I pulled from right to left because I do not have reverse checked. If I had reverse checked, I would have pulled left to right. Notice the gradient style I have selected and that the tool is in normal blend mode and that transparency has been enabled.
    I should also mention that I pulled from pretty close to where the two images join and only pulled maybe a centimeter worth of drag.
    Yellow line shows start and stop point of tool drag. *You can drag more than once if the gradient is too thin at the join.
    The reason you want to hold in the shift key as you drag the gradient is because this gives you an even pull...makes a straight line. Without using the shift key you can get a wonky uneven join.

  • Downloaded a trial version of the "Living Earth Desktop" screensaver and cannot get rid of it. I deleted the download and cannot find it anywhere else on my mac. I will change the desktop image and the living earth image will pop back up minutes later.

    Downloaded a trial version of the "Living Earth Desktop" screensaver and cannot get rid of it. I deleted the download and cannot find it anywhere else on my mac. I will change the desktop image and the living earth image will pop back up minutes later. Does anyone know how I can make this image stop taking over my desktop? Thanks!
    http://download.cnet.com/Living-Earth-Desktop/3000-2049_4-10789812.html
    This is the website.

    IF you know the exact file name of the download, you can search for it in the spotlight.
    (This icon) in the upper right corner.
    If you don't know the exact file name, you may have to redownload it so you can see it.
    I would also try doing a reboot after you change your desktop background to what you want.

  • Background image obscures the auto page numbering

    I have an 80 page book that I want to have automatic page numbering. All pages have a background image that bleeds off the page. The background image changes on every page.
    The document is currently set up with individual image boxes on each page rather than on the master page. The problem i have is with the image obscuring the page numbering on each page. Trying to correct this I went back into the master pages to lay down a master image box bleeding off the page and the automatic page numbering on the layer above it. Testing this on a test document everything works fine. But as soon as i attempt to go into a regular page and change that master image the numbers disappear.
    What is the proper way to change an image from the applied master page so that it doesn't obscure the page numbers?

    Great suggestion for using layers, I'm accustomed to using them all the time in Illustrator and forgot about that option in this case. It worked perfectly to place the page numbers on the master page on a second layer positioned on top and applying master page to all document pages. It brought the numbers up to the top level.
    Thanks so much for the solution.

Maybe you are looking for

  • Adding fields to ALV output list in Tcode S_ALR_87012357

    Hi, I need your help to insert new fields in output at standard t-code S_ALR_87012357 for GST Report. Report name is RFUMSV00. The add/insert columns are 1)Vendor Description, 2)SGD Gross Amt(100% tax Reporting  curr) 3)SGD Tax Base Amt(100% Tax Repo

  • Error "Invalid Report Object" when running any CR

    Hi, I have installed BO XI V3.1 and upgraded to 1.4 level. However when logged into the infoview app, if i browse to any 2008 report i have uploaded into the enterprise system and double click to run i get the error "Invalid Report Object". This is a

  • R9 280X Max HDMI Resolution?

    I have ordered an MSI R9 280X GAMING 3G card to run a 4K TV as a monitor at 3840x2160.  I thought all of the R9 280X cards were able to output this 4K 3840x2160 resolution on the HDMI port.  But, based on the specifications list on MSI's website for

  • Browser Cookies in Mac

    Hello, Im developing an application in Actionscript3 in Flash for Windows, but recently I try to develop the same code in Flash for Mac and the application don't manage the browser session cookie. Flash have any security restriction in mac??? How Fla

  • Documents won't download

    I'm using a Learning Lab, so we have 15 iPads syncing to iCloud. Most documents download perfectly well, but a few fail to download in Pages, Word or PDF format. I have tried these things: Change the document on the original iPad, forcing a new save