Creating an ImageIcon from others ImageIcon

Hi,
I want to write a method that create an ImageIcon object from two ImageIcon objects passed.
ImageIcon createImageIcon(ImageIcon img1, ImageIcon img2) {
ImageIcon img;
return img;
The returned ImageIcon displays as the two img1 and img2 placed side by side.
Thanks very much,
Charly

Thanks to camickr and stevops,
this is my working method (mainly the camickr code).
     public static ImageIcon createImageIcon(ImageIcon icon1, ImageIcon icon2) {
          int width = Math.max(icon1.getIconWidth(), icon2.getIconWidth());
          BufferedImage image = new BufferedImage(width, icon1.getIconHeight() + icon2.getIconHeight(), BufferedImage.TYPE_INT_RGB);
          Graphics g = image.createGraphics();
//          g.drawImage(icon1.getImage(), 0, 0, icon1.getIconWidth(), icon1.getIconHeight(), null);
//          g.drawImage(icon2.getImage(), 0, icon1.getIconHeight(), icon2.getIconWidth(), icon2.getIconHeight(), null);
          icon1.paintIcon(null, g, 0, 0);
          icon2.paintIcon(null, g, 0, icon1.getIconHeight());
          g.dispose();
          return new ImageIcon(image);
     }Bye

Similar Messages

  • How to create an ImageIcon from other ImageIcon's part?

    I have an ImageIcon instance and want to create an other one from the specified part of the initial icon.
    How can this be done??
    Thanks. Boris.

    If I were you, I would create a BufferedImage and paint the ImageIcon into it. You have the choice of either :
    - in the paint method itself, modify the clip bounds so as to make it only paint the desired region
    - or paint the image completely and then use BufferedImage's getSubimage method
    Either way, you'll get a BufferedImage that you can use to create your target ImageIcon

  • Can not open JPEG files and can not create JPEG files from other software

    Can not open JPEG files and can not create JPEG files from other software (For example from Solidworks).
    When I try to right click on a JPEG, a notice window appears written: "Windows Explorer has stopped working - Windows is
    checking for a solution to the problem" and then the notice box disapears, the desktop appears and I can continue working.
    From the other side - If I try to save as JPEG a screen of Solidworks (like a view of a part) the Solidworks falls but the JPEG
    is created (I can see its name in the directory I created it).
    I can open the JPEGS with the Paint software if I want but not with the Windows Photo Viewer.
    I have the feeling that the Windows Photo Viewer disapeared from my computer - just a feeling.
    I will appreciate your assistance.
    Avi T. 2014

    Hi,
    Did Windows Photo Viewer option appear when you right click the JPEG file and select open with?
    I would like suggest you use Clean Boot to troubleshoot if there is third-party software conflict:
    How to perform a clean boot in Windows
    http://support.microsoft.com/kb/929135
    Karen Hu
    TechNet Community Support

  • "Create Simple document" from other objects

    Scenario: Creating a document using option "Create Simple document" from other objects
    I have created a document type and defined the object link for Functional Location with option "create simple document"
    When clicking on create icon on the additional data tab on IL02 screen, The system asks for the document type and then the file to be uploaded.
    The document type that i have defined has the Description filed as mandatory field and hence i am not able to create the document.
    However, for the Document type when i set the description field as not mandatory the system creates DIR. But this DIR has no description.
    Please let me know if there is a BADI, using which i could set the Functional location name as the description OR if there is some enhancement by which the user is asked to enter the description when creating the document.
    Warm Regards,
    Vivek Mohankumar

    Hi Vivek,
    After my tests I would like to inform you that this is                  
    the standard system behavior as the document description field is       
    maintained as mandatory in transaction DC10. Please note that for the   
    simple creation of documents this should not be set as a mandatory      
    field.                                                                               
    The creation mode can be defined in transaction DC10 for each object    
    under 'Define object links'.                                                                               
    Please note that the value "1" for the creation of documents is used    
    to enable a user to simple attache a word file to an object             
    without going to the transaction CV01n. Therefore the system behaviour  
    is different then creating a document by CV01n and attaching a          
    file to it. With simple creation mode there should not be any           
    mandatory fields as the user cannot enter anything during the creation  
    process.                                                                               
    However, you can change the behaviour how the document is created by    
    MM02 transaction if you change the customizing in transaction DC10      
    like this:                                                                               
    If you maintain the value "2" for creation of documents, the user is    
    put to transaction CV01n and then the description can be entered. So    
    maybe this would solve the issue.  
    Regarding a useful BADI I can only recommned you to test BADI DOCUMENT_OBJ1,
    DOCUMENT_OBJ2 or DOCUMENT_MAIN01 for fill the description field.
    I hope this information could be useful for you and help to avoid the   
    mentioned error message.                                                                               
    Best regards,
    Christoph

  • FM to create role derived from other role

    Hi,
    I have to create roles derived from other roles. i need FM which can create roles derived from other roles. can anybody help me.
    Thanks in advance.

    Try BAPI_BUPA_ROLE_ADD_2
    Refer: http://abap.wikiprog.com/wiki/BAPI_BUPA_ROLE_ADD_2

  • How to create view/table from other user's view/table

    Hi all
    I'm using Oracle database 10g.
    I create table/view on user XXX, how to I create table/view on user YYY from user XXX.
    Thankyou,
    Thiensu2810

    user8248216 wrote:
    Hi all
    I'm using Oracle database 10g.
    I create table/view on user XXX, how to I create table/view on user YYY from user XXX.
    Thankyou,
    Thiensu2810grant select on xxx.table_name to yyy;
    create table/view table/view_name as select * from xxx.table_name;

  • Open encrypted SQL Lite created in flex from other languages

    Hi,
    How open/decrypt encrypted database sqlite from air in other languages as c++,c or java?, Because after encrypt it in flex I can not open it any other languages

    The following example shows how you can restrict which characters a user can enter into a Spark TextInput control by setting the restrict property in Flex 4.
    http://blog.flexexamples.com/2009/04/21/restricting-which-characters-a-user-can-type-in-a- spark-textinput-control-in-flex-gumbo/

  • How to create iCal events from other applications?

    I want to create event linked with a certain document, e.g. when I've finishes a letter in Pages or in TeXShop, I want to create an event in iCal for reminder. I know, that I can in iCal create events and add the link to the file into the URL field of an event. But I want in Pages, TeXShop, Numbers, … to click: »Create reminder in iCal on <date>.«
    Is there a way for it?

    Cody,
    Read: http://discussions.apple.com/thread.jspa?messageID=8314404&#8314404
    You can use Firewire Target Disk mode: http://support.apple.com/kb/HT1661 to transfer the appropriate iCal files.
    ;~)

  • Creating po in me21n with copy from other po

    Can any one tell the procedure to create PO copying from other PO.
    Edited by: Csaba Szommer on Jan 18, 2012 8:06 AM

    Hi,
    Option 1: Goto ME21N, In item Overview move to right side to 4th last column "Purchasing Doc." enter your PO number & press enter, PO will get copied if 1 item is there , otherwise if more than 1 item in PO then it will ask for which item Number you want to copy.
    Option 2: Enter ME21N T.Code
    Click u201CDocument Overview onu201D
    Click u201CSelection Variantu201D and Select Purchase Orders and Enter your PO No. & execute
    you will be able to view in document overview the PO No & Item No,
    Select the PO you need to copy & Click u201CAdoptu201D and you will see all PO details related copy to new PO which you can save.
    Option 3: Enter ME21N T.Code
    Click u201CDocument Overview onu201D
    Click u201CSelection Variantu201D and Select Purchase Orders and Enter your PO No. & execute
    you will be able to view in document overview the PO No & Item No,
    Now select 1st item and press Shift button(or you can also use Ctrl button on your keyboard for randomly selecting the line item) & with mouse select all line items and click 'Adopt' button (next to selection variant button).
    All the 100 items will get copied in the New PO.
    Refer below link for clarification,
    [Copying old PO to New PO|Re: Copy the Purchase Order]

  • Create package with prompt from other application

    Hi Experts!
    I need to create a package in the planning application. In the screen selection I need some dimensions of my planning cube and one dimension of the Ownership application. I don't have any problem with the current application dimension, but I need to retrieve the members of INTCO dimension from Ownership because the user should make the selection. Is it possible to create a prompt from other application?
    Thanks!!

    I create the package in Planning application: 
    PROMPT
    (SELECTINPUT,,,"Selction members","%ENTITY_DIM%,%CATEGORY_DIM%,%TIME_DIM%,%CURRENCY_DIM%,INTCO")
    When i try to select one member of INTCO dimension it appear the following message: "Dimension INTCO is not found". BPC is not finding this dimension because it pertain to another application.

  • Creating ImageIcon from .ICO files

    Can i use an icon (.ICO) to create an Icon or an ImageIcon for a JButton?
    Thank you

    if you save it as a .gif file, you CAN make it transparent. use paint in windows, or grip in unix... i know for sure that these graphics editors can make a .gif background transparent.

  • Creating ImageIcon from Image is very slow

    Hi I have a program which reads a number of files which may contain (amongst other things) image data in various formats such as JPG.I read scale this down into an image object fine, and then I want to display a small version of it on screen so I put the scale dimage into an ImageIcon which i display later using a JLabel.
    Anyway it runs very slow , the funny thing is using JProbe Ive tracked the problem down to creation of the ImageIcon constructor, the actual thumbnail image creation is very quick.
    Why does ImageIcon take so long or is there a simple way of displaying the image in a Swing Application
    without using JLabel.
    BufferedImage bi = ImageIO.read(new DataInputStream(new ByteArrayInputStream(imageData)));
    Image thumbnaiImage = image.getScaledInstance(20,20Image.SCALE_FAST);
    ImageIcon thumbnail     = new ImageIcon(thumbnailImage);

    If you're not too picky about the image quality (and I see you're using SCALE_FAST), you can set the
    source subsampling on your ImageReadParam so that you never construct the large image: you start
    with the thumbnail.
    import java.awt.*;
    import java.awt.image.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import javax.imageio.*;
    import javax.swing.*;
    public class AllThumbs {
        public static void main(String[] args) throws MalformedURLException {
            String prefix = "http://www3.us.porsche.com/english/usa/carreragt/modelinformation/experience/desktop/bilder/icon";
            String suffix = "_800x600.jpg";
            JPanel p = new JPanel(new GridLayout(0,3));
            for(int i=1; i<9; ++i) {
                try {
                    p.add(getThumb(new URL(prefix + i + suffix), 200, 150));
                } catch (IOException e) {
                    System.out.println(e.getMessage());
            JFrame f = new JFrame("AllThumbs");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(p);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        public static JLabel getThumb(URL url, int maxWidth, int maxHeight) throws IOException {
            String suffix = getSuffix(url);
            Iterator readers = ImageIO.getImageReadersBySuffix(suffix);
            if (!readers.hasNext())
                throw new IOException("No reader for suffix " + suffix);
            ImageReader reader = (ImageReader) readers.next();
            reader.setInput(ImageIO.createImageInputStream(url.openStream()), true, true);
            int w = reader.getWidth(0), h = reader.getHeight(0);
            int subsampling = Math.max(1, Math.max(w/maxWidth, h/maxHeight));
            ImageReadParam param = reader.getDefaultReadParam();
            param.setSourceSubsampling(subsampling, subsampling, 0, 0);
            BufferedImage image = reader.read(0, param);
            String path = url.getPath();
            String text = path.substring(1+path.lastIndexOf('/'));
            JLabel label = new JLabel(text, new ImageIcon(image), SwingConstants.CENTER);
            label.setHorizontalTextPosition(SwingConstants.CENTER);
            label.setVerticalTextPosition(SwingConstants.BOTTOM);
            label.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
            return label;
        public static String getSuffix(URL url) throws IOException {
            String path = url.getPath();
            int dot = path.lastIndexOf('.');
            if (dot == -1)
                throw new IOException("No . in " + path);
            return path.substring(1+dot);
    }It is also possible for there to be thumbnail images stored in an image file. (These thumbnails
    don't even have to be related to the main image.) ImageIO has methods to read these directly,
    so if you have control over your image files you can create them with thumbnails in place.

  • How to remove an ImageIcon from a JPanel.

    I'm kind of new to java, and I'm trying to write a simple program that will change a picture in a window when a button is clicked. Is there a simple way to remove an ImageIcon from a JPanel. I tried the remove() method, but it says there is no constructor to handle remove(ImageIcon). This is the error I'm getting. I can/will post my code if you think it's necessary, but I didn't think it would be needed.
    PicChanger.java:64: cannot find symbol
    symbol : method remove(javax.swing.ImageIcon)
    location: class javax.swing.JFrame
    frame.remove(ii);
    ^

    Oh wow, that changes everything. Thanks for the information! Can't believe I missed that.

  • How can I remove the gradient background & border from an ImageIcon?

    Problem1: Hey, I have a program that randomly displays a stop sign that I'm supposed to click on as fast as I can. And I created a gif with the stop sign, with it's background transparent. But when I added it to my application using an ImageIcon, whatever's supposed to be transparent in the gif is shown up as a gradient. There's also a border around the ImageIcon. Is there any way to get rid of these? Thanks
    Problem 2: I also have a background for my entire application, but it stays the same size no matter if I maximize the application or run it on a different screen size. Is there any way to scale a background (it's animated), to the full screen?
    Thanks again! It's for a project due tomorrow. I'm doing final touches.
    Here's some of my code. It's really long, so I took out what I think is related. JButton stopSign1 = new JButton();
    this.getContentPane().add(stopSign1,null);
             ImageIcon stopSign = new ImageIcon("Dead_End.gif");
             stopSign1.setBounds(new Rectangle(randomX, randomY, 150, 150));
             stopSign1.setIcon(stopSign);
             stopSign1.setVisible(false);

    Try stopSign1.setBorder(null);
    stopSign1.setOpaque(false);Also, in future, post Swing questions in the Swing forum.

  • The correct way to init an ImageIcon from gif file ?

    What is the correct ( portable, portable, always works etc... ) way to do this :
    ImageIcon icon = new ImageIcon("some_picture.gif"); ?
    use MyClass.class.getResource("some_picture.gif") ?
    Use absolute path ? Relative ? Relative to what ?
    Urgent help needed !
    Our project has a complex structure, something like :
    com.x.y.z.ClassA
    picture in :
    com/x/y/stuff/pics/some_picture.gif
    so we use in ClassA :
    getClass().getResource("../stuff/pics/some_picture.gif");
    But that only works with plain files, it fails when run from a jar !
    ( all the class and gif files are inside the jar )
    We need it to work when executed from files and from jar !
    Also on multiple platforms !
    Help!
    stein

    I use:
    private final static ImageIcon myIcon = new ImageIcon(MyClass.class.getResource("myIcon.gif"));
    and later on use that icon in a JTree and it works. And I have it in a jarfile as well. Relative means that it's relative to where you have your classfiles. Absolute means the complete path (C:\Temp\MyIcon.gif).
    You could use absolute path if you're not sure where your classfiles are..
    Good luck

Maybe you are looking for