Results 1 to 2 of 2
  1. #1
    asmitarnd is offline Member
    Join Date
    Mar 2011
    Posts
    22
    Rep Power
    0

    Default Displaying multiple images in java

    hi,
    I m trying to display multiple images on a single JFrame.I m able to display but the problem i m facing is that though my images are of different sizes when they r displayed on single JFrame they appear to be of same size and that too also very small.Can anyone help me?Its urgent.I have tried with this

    /******displaying images on single JFrame********/

    public class TestClient
    {

    public ImageDrawingComponent imageCompent;
    public ImageDrawingComponent imageCompent1;
    public ImageDrawingComponent imageCompent2;
    public ImageDrawingComponent imageCompent3;
    public ImageDrawingComponent imageCompent4;
    public ImageDrawingComponent imageCompent5;
    public ImageDrawingComponent imageCompent6;
    public ImageDrawingComponent imageCompent7;

    public static void main(String[] args)throws Exception
    {
    JFrame f = new JFrame(" test");
    f.setSize(1000, 1000);
    f.addWindowListener(new WindowAdapter()
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    });


    TestClient testClient=new TestClient();
    ArrayList<ImageDrawingComponent> arrayList=new ArrayList<ImageDrawingComponent>();
    arrayList.add(testClient.imageCompent);
    arrayList.add(testClient.imageCompent1);
    arrayList.add(testClient.imageCompent2);
    arrayList.add(testClient.imageCompent3);
    ImageDrawingComponent jp=arrayList.get(0);
    ImageDrawingComponent jp1=arrayList.get(1);
    ImageDrawingComponent jp2=arrayList.get(2);
    ImageDrawingComponent jp3=arrayList.get(3);
    f.getContentPane().add(jp);
    f.getContentPane().add(jp1);
    f.getContentPane().add(jp2);
    f.getContentPane().add(jp3);
    f.setLayout(new FlowLayout());
    f.setVisible(true);
    }

    public TestClient()
    {
    imageCompent = new ImageDrawingComponent("img1.jpg");
    imageCompent1 = new ImageDrawingComponent("img2.jpg");
    imageCompent2 = new ImageDrawingComponent("test.jpg");
    imageCompent3 = new ImageDrawingComponent("scr-shot.jpg");
    }

    /***********browisng images********/

    public class ImageDrawingComponent extends JPanel// extends JComponent//Container
    {
    BufferedImage img;
    Graphics2D g2;
    public ImageDrawingComponent(String fileName)
    {
    try
    {
    img=ImageIO.read(new File(fileName));

    }
    catch (IOException e)
    {
    e.printStackTrace();
    }
    currentRate=1;
    }
    public void paintComponent(Graphics g)
    {
    g2=(Graphics2D)g;

    AffineTransform at = AffineTransform.getScaleInstance(currentRate, currentRate);
    g2.drawImage(img, at, null);


    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

Similar Threads

  1. Displaying multiple images
    By asmitarnd in forum AWT / Swing
    Replies: 2
    Last Post: 04-19-2011, 12:14 PM
  2. Replies: 0
    Last Post: 11-28-2009, 03:37 AM
  3. Displaying large images
    By pir8ped in forum AWT / Swing
    Replies: 2
    Last Post: 01-21-2009, 09:20 PM
  4. [SOLVED] Need help in displaying images
    By kirly in forum Advanced Java
    Replies: 3
    Last Post: 10-21-2008, 05:36 AM
  5. Images not displaying in JSP in IE7
    By chadscc in forum Advanced Java
    Replies: 0
    Last Post: 11-13-2007, 03:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •