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.