Results 1 to 3 of 3
  1. #1
    rahil.khan is offline Member
    Join Date
    Oct 2014
    Location
    NEW DELHI
    Posts
    41
    Rep Power
    0

    Post how can i decrease the size of image?

    Java Code:
     
    import java.awt.*;
    import javax.swing.*;
    public class addImage extends JFrame {
    	private ImageIcon img1;
    	private JLabel label1;
    	private ImageIcon img2;
    	private JLabel label2;
    		
    	addImage(){
    		img1 = new ImageIcon(getClass().getResource("Image/1.jpg"));
    		label1 = new JLabel(img1);
    		add(label1).setSize(100, 100);
    		
    		System.out.println();
    		
    		img2 = new ImageIcon(getClass().getResource("Image/2.jpg"));
    		label2 = new JLabel(img2);
    		add(label2).setSize(50, 50);
    		
    	}
    	
    	public static void main(String[] args) {
    		addImage ai = new addImage();
    		ai.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		ai.setVisible(true);
    		ai.pack();
    		ai.setTitle("Image Program");
    	}
    
    }
    i want to decrease the size of image 2 but code on line 18 is not working why????

    i have attached the output kindly find it.
    Attached Thumbnails Attached Thumbnails how can i decrease the size of image?-capture.png  
    Last edited by rahil.khan; 03-02-2015 at 08:33 PM.

  2. #2
    rahil.khan is offline Member
    Join Date
    Oct 2014
    Location
    NEW DELHI
    Posts
    41
    Rep Power
    0

    Default Re: how can i decrease the size of image?

    Help me...

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: how can i decrease the size of image?

    Do you at this point know what that

    Java Code:
    ai.pack();
    call actually does? I am assuming you don't, because your code proves that you don't know what it does. I would start by learning about that and how layout managers work.

    Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Decrease array size without losing data
    By lorreTheGreat in forum New To Java
    Replies: 7
    Last Post: 02-27-2013, 04:24 PM
  2. Replies: 4
    Last Post: 08-09-2012, 07:18 PM
  3. Setting frame size to the size of an image
    By Yoruichi in forum AWT / Swing
    Replies: 5
    Last Post: 04-22-2009, 05:37 PM
  4. gridbaglayout: increase/decrease size of components.
    By newtojava7 in forum New To Java
    Replies: 2
    Last Post: 01-28-2008, 08:22 AM
  5. how to set an image size
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 09:27 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
  •