Pictures on top of each other

Hi all!
I have a question of how I place several images on top of each other. I have an application and I place a background image in it. Then I want to have images "on top" of the background imgage. All images is in the format .png, which can be transparent.
My problem is that when I add an transparent image, I dont see the background image through it. Instead I get the default background color (something grey/blue).
Can somebody help me with:
1) How do I put the background picture in my JFrame (I'm not sure I'm doing this correctly)
2) How do I display .png images in the JFrame so that I see the background through it?
Regards,
Andreas

I wrote example for AWT because in SWING it can be done very easy. Run this code, it runs fine. Use only your image files.
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.awt.*;
import java.awt.event.*;
public class ImageTest extends Canvas implements WindowListener {
public static void main(String[] args) {
Frame frame = new Frame("Image testing");
ImageTest instance = new ImageTest();
frame.add(instance);
frame.addWindowListener(instance);
frame.pack();
frame.setVisible(true);
public Dimension getPreferredSize() {
return new Dimension(256, 256);
BufferedImage backgroundImage;
BufferedImage alphaImage;
void initImage() {
Image img = getToolkit().createImage("D:\\temp\\JavaTests\\viewcode.jpg");
Image bkImage = getToolkit().createImage("D:\\temp\\JavaTests\\SolarEclipse.jpg");
MediaTracker Mt = new MediaTracker(this);
Mt.addImage(img, 0);
Mt.addImage(bkImage, 1);
try{
Mt.waitForAll();
}catch(Exception e){};
BufferedImage bi = new BufferedImage(img.getWidth(this), img.getHeight(this), BufferedImage.TYPE_4BYTE_ABGR);
alphaImage = new BufferedImage(bkImage.getWidth(this), bkImage.getHeight(this), BufferedImage.TYPE_4BYTE_ABGR);
Graphics gr = bi.getGraphics();
gr.drawImage(img, 0, 0, this);
backgroundImage = (BufferedImage)bi;
gr = alphaImage.getGraphics();
gr.drawImage(bkImage, 0, 0, bkImage.getWidth(this)/2, bkImage.getHeight(this)/2, bkImage.getWidth(this)/2, bkImage.getHeight(this)/2, bkImage.getWidth(this), bkImage.getHeight(this), this);
Color bl = new Color(0, 0, 0);
for (int x=0; x<bkImage.getWidth(this); x++)
for (int y=0; y<alphaImage.getHeight(this); y++) {
Color c = new Color(alphaImage.getRGB(x,y));
int r = c.getRed();//x*4;
int g = c.getGreen();//y*4;
int b = c.getBlue();//255 - (x+y)*2;//Math.abs(y*8-255);
// Make transparent colors, which look like black
int a = (r == b && g == b && r < 100 && g < 100 && b < 100)?0:255;
int vv = (a<<24) | (r<<16) | (g<<8) | b;
alphaImage.setRGB(x, y, vv);
public void paint(Graphics gfx) {
if (backgroundImage == null)
initImage();
gfx.drawImage(backgroundImage, 0, 0, this);
int i = 0;
int delta = 100;
gfx.drawImage(alphaImage, i, i, this);
gfx.drawImage(alphaImage, i + delta, i + delta, this);
gfx.drawImage(alphaImage, i + delta*2, i + delta*2, this);
gfx.drawImage(alphaImage, i + delta*3, i + delta*3, this);
gfx.drawImage(alphaImage, i + delta*4, i + delta*4, this);
gfx.drawImage(alphaImage, i + delta*5, i + delta*5, this);
void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
public void windowActivated(java.awt.event.WindowEvent windowEvent) {
public void windowClosed(java.awt.event.WindowEvent windowEvent) {
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
System.exit(0);
public void windowDeactivated(java.awt.event.WindowEvent windowEvent) {
public void windowDeiconified(java.awt.event.WindowEvent windowEvent) {
public void windowIconified(java.awt.event.WindowEvent windowEvent) {
public void windowOpened(java.awt.event.WindowEvent windowEvent) {

Similar Messages

  • I recently did the 5.3 update to my Apple TV and now it is running sluggish and things keep freezing and then pictures are loading on top of each other. Then I did a hard reset today and now the WWDC app is gone. Anyone else having these issues?

    I recently did the 5.3 update to my Apple TV and now it is running sluggish and things keep freezing and then pictures are loading on top of each other. Then I did a hard reset today and now the WWDC app is gone. Anyone else having these issues?

    I have been having problems with my atv 3 not transmitting/receiving 5.1 surround. Whether I stream from my computer or watch movies, I am getting no 5.1 audio. The atv won't even show the option for surround. I tried to restore and reset the device but it didn't help.
    I haven't had any problems with missing apps or freezing or anything similar to what you are experiencing. This update has many bugs. Other threads have reported even more problems. Hopefully I can go back to the previous update.

  • On some pages the text from more than one paragraph stack up on top of each other, like writing something then writing something else on top of it.

    On some pages the text from more than one paragraph stack up on top of each other, like writing something then writing something else over the top of it. Some pages will run text and pictures together, like a car rear-ending another or a train pile up. Other pages will cut an image or text short, i.e. it will display a portion of the top of the image or text but not the rest. This happens on Amazon for example, the section where it says "Customers who looked at this also looked at" will allow only a certain amount of the upper portion of the description immediately below the picture of the product but below that section everything is fine until I get to another section displaying more products and their descriptions and then it cuts the bottom portions off again. I've noticed this behavior mostly in the sections with product photos, the text sections seem okay. YouTube also displays this behavior. It's even doing it on this page right now. Below this box I can read "The more information you can provide the better chance your question will be answered " , but directly below that in the next sentence I can see the start of it with "Troublshootin" and the "Automatically Add" in a green field covering the "g". The next clear text is "A window will open in the top corner. Click Allow, and then click Install. If the automated way doesn't work, try these manual steps." I tried turning of pre-fetching, clearing history, cookies, and cache, scanning for malware with Avast and Windows Defender all to no avail. It began when I upgraded from dial up to DSL via AT&T Uverse. I have a Motorola NVG510 modem. The modem was replaced an hour ago along with new dedicated lines and DSL/Phone splitter from the box by an AT&T technician to make sure my incoming lines were up to par. He ran a connection test and verified everything is up to standards. IE does not display this behavior. I am running Firefox20.0.1 and all previous versions have acted the same way since I upgraded to DSL about 3 months ago.

    If you have increased the minimum font size then try the default setting "none" in case the current setting is causing problems.
    *Tools > Options > Content : Fonts & Colors > Advanced > Minimum Font Size (none)
    Make sure that you allow websites to choose their fonts.
    *Tools > Options > Content : Fonts & Colors > Advanced: [X] "Allow pages to choose their own fonts, instead of my selections above"
    It is better not to increase the minimum font size, but use an extension to set the default page zoom to prevent issues with text not being displayed properly.
    You can use an extension to set a default font size and page zoom on web pages.
    *Default FullZoom Level: https://addons.mozilla.org/firefox/addon/default-fullzoom-level/
    *NoSquint: https://addons.mozilla.org/firefox/addon/nosquint/

  • Images are on top of each other.

    Forgive me, but I will explain this as best I can. We just got our iMac. We have 2 cameras that we use. So I imported some pictures from church last night. They show up in my library at the bottom AND the top (as if they were imported twice). Now, if I'm at the top of my library and double-click on an image, it brings me to the editing room. But now instead of the picture being the one from church, the enlarged picture is a construction picture taken by another camera (and the picture in the toolbar area is still the picture from church - they don't match). However, those same church pictures at the bottom of the library don't have that problem - they are what they should be. And there are some other images like that, too (but not all of my pictures have done that). And they don't have the same file name, so it's not like iPhoto is confused by that. Also, if I'm scrolling through, I will see pictures from church, and when I stop scrolling, the construction pictures come in and take their place.
    Any ideas??? Why is it double-importing and placing images on top of each other like that? Am I doing something wrong?
    Thanks for any help you might have on this.
    iMac   Mac OS X (10.4.9)  

    Vixon
    Welcome to the Apple Discussions.
    Try rebuilding the database. Hold down the apple and option (or alt) keys and launch iPhoto. Use the resulting dialogue to rebuild. Choose the top three options.
    Regards
    TD

  • Safari 5.1 now is garbled with many of the sites having lines on top of each other. Is any one else having that issue? If so, how did you resolve it? Thanks in advance for any help.

    Safari 5.1 now is garbled with many of the sites having lines on top of each other. Is any one else having that issue? If so, how did you resolve it? Thanks in advance for any help.

    "Did you make the .psd file with a transparent background (checkerboard) in Photoshop? And when you placed it in AI did you choose the top option Convert Photoshop Layers to Objects?"
    Yep, and it still didn't work.
    But I figured what I did wrong: I was selecting both the text and the heart, and then I was doing the whole Object>Wrap Text>Make thing, as opposed to just selecting the heart and doing it. Once I did it, I moved the heart around on top of the text, and it "made room" for the pic, wrapping itself around the heart.
    Thanks so much, and thanks A MILLION for being so patient.
    Jeez, when can I get some textbook to learn all the intricacies of Illustrator?

  • Since my iPad IOS was updated to 7.0.4, when I send a Pages doc as a Word docx to my kindle the text is all scrunched up down one side as if the letters are on top of each other.  It worked find before and the docx are OK when imported to Word.

    Since my iPad 2 was updated to IOS 1.0.4, I cannot send a docx from Pages to my kindle.  I can to my PC and open it in Word.  But when I send a pages document and select Word as the format, the letters appear on my kindle screen down the left side, printed on top of each other.  It worked fine before the upgrade.  Any suggestions? 

    What version of Pages are you using? Did you upgrade to Pages 2.1 for iOS?

  • A video on any site is shown double, one on top of each other!

    When ever I want to see a video, no matter what site it is, the screen, where the video is on, shows two images of the video. Basically, the video is condensed into two, one on top of each other, making them wide, but I dont know why there show two!!

    This seems to have happened after the latest Adobe Flash Player update. Might be an issue of compatibility with Firefox, since in Internet Explorer the problem doesn't appear. Haven't tried any other browsers yet.
    To me, it seems that the two images that appear are similar to the ones used in making 3D movies, but instead of displaying them overlapped they are displayed separately. This is just a wild guess and I have no actual proof to back this up.
    PS: I am also using Firefox 3.6.13 on Windows XP.
    Later edit: I have found a workaround for this issue. Right-Click on any improper displayed video and choose Settings. On one of the tabs found there is a checkbox "Enable Hardware Acceleration". It was enabled for me, after disabling it and restarting the browser the video was back to normal.

  • In FCPX can I stack clips of multiple angles on top of each other and choose what parts I want to make my movie out of?

    Hi there
    I'm debating whether to purchase FInal Cut Pro X or not and I'm new(ish) to video editing.
    What I have done so far is produce a music video mimed to audio and shot at about 20 different angles. Each angle is the length of the ENTIRE song, not just snipets.
    What I want to be able to do is have those 20 videos sitting stacked up on top of each other (completely synced to the audio) and be able to choose what parts of what video I make my final video out of.
    So I want to be able to tell the system to start at angle 1, then at a specific time move to angle 6, then angle 19, then back to angle 1, then angle 16 etc etc etc.
    But I dont want to cut up the parts of each camera angle first, I want to be able to select a specific part to play from each ENTIRE camera angle.
    Is this possible please? And also what is the correct terminology for this process?
    I apologise for not using the correct terminology here, as I dont know the correct words for what I am trying to explain.
    Thanks

    FCPX mulitcam editing is the most advanced of any NLE on the market at the moment.
    Read the user manual here to learn how Multiclips work.
    http://help.apple.com/finalcutpro/mac/10.0.6/#ver23c76439
    You'll want to learn about how to work with Audio Channels with multiclips, also.  Very powerful.
    http://help.apple.com/finalcutpro/mac/10.0.6/#verc1fab5f6
    Here is my article on audio channels in Multiclips.
    http://www.macprovideo.com/hub/final-cut/final-cut-pro-multiclip-audio-channel-e diting-1006

  • Sometimes text is stacked on top of each other

    Sometimes when viewing a page on the internet there is a small part of the text that is unreadable. Especially when it involves a form to fill out. There will be an area on the page that has two different sentences on top of each other. When one is a link (frequently) it can be impossible to click on. Any ideas?
    Thanks

    The few times I can recall that issue happening in Lion, it occured before the page had fully loaded. Once it fully loaded it re-arranged itself properly.
    I experienced it more frequently with older browser versions.
    Up until about a year ago I was still using OS 9 and its antiquated browser. The overlapping text issue was not uncommon with it; its growing inability to handle modern web page layouts and features was the instigator for me to get a modern machine and OS.
    If you are still using OS X 10.5 (as your specs indicate), you should probably upgrade to Snow Leopard; going on to Lion may or may not be a good idea, or even possible - there are some hardware restrictions.
    Minimum hardware specs for OS versions can be seen at these pages -
    Snow Leopard - Mac OS X v10.6 Snow Leopard - Technical Specifications
    Lion - Apple - OS X Lion - Technical specifications

  • New icons alway appear top right corner on top of each other.

    Hi All.
    When I connect to a network disc or download something to the desktop, anything that needs a new desktop icon to be created, all the newly created icons appear stacked on top of each other, like a deck of cards, in the top right hand corner. I usually have my main HD there but it refuses to stay put. I've tried the arrange and clean up options, I have also repaired permissions and run disc warrior. This is a very recent complete re install of everything, from scratch. Any other suggestions?
    Regards, Nick

    Hi Nick
    This may work.
    Open Terminal, found in Applications/Utilities.
    copy and paste this text into terminal.
    sudo rm .DS_Store
    supply your password, it will be 'invisible' as you type, Press Return/Enter key
    type
    exit
    Quit Terminal.
    Log out and log back in again.
    regards roam

  • New windows don't open on top of each other in Firefox. How can I make that happen?

    New windows don't open on top of each other in Firefox. How can I make that happen? That is, every time I open a new window, it won't open on top of the old window, and instead is positioned to the right of it. I'm on a mac. Please help.
    == This happened ==
    Every time Firefox opened
    == Today

    I see. I'm not aware of how to fix this in Firefox. Usually you want to tweak your Winow Manager preferences for opening new windows.
    Example: sawfish preferences for Linux.
    Since Mac OS X doesn't have any preferences, you have to use Applescript or another technique. I found [http://amitp.blogspot.com/2006/08/mac-os-x-window-management-spooky.html Spooky], maybe there are others. I haven't tried it, but here is the [http://www.doernte.net/spooky.html Spooky Download and Description].

  • Sites with windows with more than one page open on top of each other

    Sometimes when I go to a new site, pages load on top of each other.

    Well, I don't know if this image is going to upload, but I did a screenshot so you can see what I mean. It happens on other websites, too. Remember transparencies, the clear plastic letter-size sheets you could write on? It's like stacking 2-3 sheets on top of each other, with each sheet saying something different. It looks like a jumbled mess. And it's not pop-ups.

  • When I open TWC, the site opens twice, not right on top of each other but skewed to the right. I can read it and it won't search locations.

    For the last 3 days, when I open TWC it has two images of the site on top of each other, as if the site opened two times.

    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    *Tools > Options > Advanced > Network > Offline Storage (Cache): "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Tools > Options > Privacy > Cookies: "Show Cookies"
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode

  • On the top left of my computer screen there are what look like the bottom half of small grey and white squares stacked on top of each other. They form a line about three inches long and I cant seem to get rid of them.  Is my computer dying or being hacked

    On the top left of my computer screen there are what look like the bottom half of small grey and white squares stacked on top of each other. They form a line about three inches horizontally along the top and they cover half of the regualr bar (so half of the apple sign int he corner is covered) and I cant seem to get rid of them.  Is my hardrive crashing or being hacked?

    I have never seen DEVELOP on the menu bar for Safari, hence my query regarding testing. 
    What OS are you using and what version of Safari?
    If you want to check your HDD, Open Disk Utilities>First Aid and run Verify and Repair.
    The only remedy that I can think of that may work is an OS reinstall.
    I seriously doubt that your MBP is being hacked.
    Ciao.

  • My apps have all moved on top of each other in the top left corner if I drag them back every time I change page then change back they go back to the corner .what have I done

    My apps have all moved on top of each other in the top left hand corner of the page.every time I drag them back to where they are ghosting on the page ,then change page and back again they r back in the corner again help what have I done

    Try a Reset... press the home and sleep/lock buttons until you see the Apple logo, ignoring the slider. Takes about 5-15 secs of button holding and you won't lose any data or settings.

Maybe you are looking for

  • Ipod nano 6th generation not recognized by itunes

    Whenever i plug in my 6th generation nano (the little one with the touch screen), iTunes tells me it knows there is an iPod connected, but it cant be identified properly. Ive tried resolving it with all the help on iTunes and nothing has worked. Any

  • Connecting a Smart Card Reader to Intel iMac

    Im using a SCR331 CAC reader on my 2.5ghz MBP, I cant seem to get the system to recognize my CAC in the Keychain access list. Can someone help me out? Ive tried this link http://caconmac.openboxconcepts.com/safari, but you have to have the CAC recogn

  • Can anyone help why I am getting this error.

    I am seeing these errors when I try to test my database. I can't understand why. Does anyone have any ideas? The exact file with different field names works on a different table of the same database. Thanks for the help. Errors in ActionScript. Error

  • Can't locate iweb folder in application support

    I cant locate the iweb folder inapplication support, I'm trying to find the domain file but I've haven't succeed.

  • Decision Services Failing with operationErroredFault

    When invoking a decision service in BPEL 10.1.3.1 I sometimes experience operationErroredFault. This appears to be when the server is under load. The Process has been written to catch and retry on remoteFault and bindingFaults and the operationErrore