Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Setting the image size within a JFrame!

807599Jan 18 2007 — edited Aug 4 2007
This is the code i have implemented
import javax.swing.*;
import java.awt.*;


class SampleJFrame extends JFrame
{
	JLabel l1;
	ImageIcon image;
	SampleJFrame()
	{
		image=new ImageIcon("G:/java files1/images/aa.jpg");
		l1=new JLabel("DEDICATION",image,JLabel.RIGHT);
		l1.setSize(100,100);
		//this.setLayout(new FlowLayout(FlowLayout.RIGHT));
		this.add(l1);
	}
}


public class JFrame2
{
	public static void main(String args[])
	{
		SampleJFrame samplejframe=new SampleJFrame();
		samplejframe.setTitle("FRAMES WITH JLABELS WITH IMAGEICON");
		samplejframe.setSize(400,400);
		samplejframe.setVisible(true);
	}
}
When i run this the image occupies the entire JFrame.I want to resize it to a width of around 100,80 pixels.How can i do it?

I know when i draw a image without linking to a label i can use drawImage of Graphics class to set the size of the image.But in this case i am linking the image to the JLabel and it's occupying the entire screen and the text with the JLabel is thrown somewhere out.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 1 2007
Added on Jan 18 2007
5 comments
806 views