Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   HELP - placing picture on top of another picture in Java - JLayerPane (https://www.askmehelpdesk.com/showthread.php?t=653315)

  • Apr 22, 2012, 09:35 AM
    NerdyBoy9
    1 Attachment(s)
    HELP - placing picture on top of another picture in Java - JLayerPane
    Hi..

    I am trying to place a picture on top of another one in java..

    I have a Tshirt picture which I am going to place it in the center of my GUI
    Also I have a logo I want to put it on top of that picture

    I used JLayerPane but I guess I made mistake which I couldn't notes and solve.

    This is part of my code.


    Code:

    static JComboBox colours, sizes, logos;                                                          // Variables for drop box
    static JLabel picture, logo;                       
     
    private static String[] fileName = {"src/white.gif", "src/green.gif", // array of the file names will
                                                "src/blue.gif", "src/brown.gif",  //
                                                    "src/black.gif", "src/red.gif",  //
                                              "src/gray.gif"};                    // store the T-shirt pics.                     
     
    private static String[] logosList = {"src/likeMe.gif", "src/followMe.gif",
                                                                        "src/youtube.gif"};
     
     
    private Icon[] pics = { new ImageIcon(fileName[0]), new ImageIcon(fileName[1]),                    // array of images will store
              new ImageIcon(fileName[2]), new ImageIcon(fileName[3]), new ImageIcon(fileName[4]),  // the the all images.
                                            new ImageIcon(fileName[5]), new ImageIcon(fileName[5]), new ImageIcon(fileName[6])};
     
    private Icon[] logs = { new ImageIcon(logosList[0]), new ImageIcon(logosList[1]),  //To hold logos for T-shirts.
                                    new ImageIcon(logosList[2])};
     
     
    inside my constructor
     
                            pnlNorth = new JPanel ( new GridLayout ( 3, 3));
     
     pnlNorth.add(colours = new JComboBox (fileName));                      // put the colours list in the ( fileName array ) in list for us.
                            pnlNorth.add(sizes = new JComboBox ( sizeList )); // put the sizes list in the ( sizeList array ) in list for us.
                            pnlNorth.add(logos = new JComboBox ( logosList ));// put the logos list in the ( logoList array ) in list for us.
                            pnlNorth.add(lblCustomizeYourOrder);
     
                            // Then add it to the container.
                            add(pnlNorth, BorderLayout.NORTH);
     
     
     
     
            // JLayerPane to put 2ed layer "logo" on top of the picture.
                            jlayerPane = new JLayeredPane();
                            jlayerPane.setPreferredSize(new Dimension (300,300));
                            jlayerPane.setLayout(new FlowLayout());
     
                            picture = new JLabel (pics[0]);
                            logo = new JLabel (logs [0]);
     
                            // Manually set layout the components, and add it.
                            jlayerPane.add(picture, new Integer (50));
                            jlayerPane.add(logo, new Integer (49));
                            // Add the JLayerPane to the container.
                            add(jlayerPane);
     
                            // Manually set layout the components.
                            picture.setBounds(600, 100, picture.getWidth(), picture.getHeight());
                            logo.setBounds(600, 100, logo.getWidth(), logo.getHeight());



    Everything perfect except placing the logo on the top of the tshirt
    How can I fix my code to place the logo on the tshirt.
    The output it attached as picture..

    Thanks guys..

  • All times are GMT -7. The time now is 05:51 AM.