Hi I am trying to set the size of JPanel in JFrame but I am unable to achieve this. How can I achieve my desired output?
Here is my code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Sample extends JFrame
{
private JPanel panel;
private JLabel label1;
public Sample()
{
panel = new JPanel();
panel.setBackground(Color.YELLOW);
panel.setBounds(100, 100, 100, 100);
ImageIcon icon1 = new ImageIcon("E:\\image\\ZooDelhi\\1.jpg");
label1 = new JLabel(icon1);
label1.setLocation(0,0);
panel.add(label1);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().add(panel);
this.setSize(500,500);
this.setVisible(true);
setLayout(null);
}
public static void main (String[] args) {
new Sample();
}
}
Thanks in advance.