Pages

Add JPanel into JFrame

Source code below will show you, how to add a JPanel into JFrame.

**************************************************************************
COMPLETE SOURCE CODE FOR : AddJPanelIntoJFrame.java
**************************************************************************


import javax.swing.JPanel;
import javax.swing.JFrame;

public class AddJPanelIntoJFrame
{
public static void main(String[]args)
{
//Create a panel
JPanel panel=new JPanel();

//Create a window using JFrame with title ( Add JPanel into JFrame )
JFrame frame=new JFrame("Add JPanel into JFrame");

//add created panel into JFrame
frame.add(panel);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size to :
//Width : 400 pixels
//Height : 400 pixels
frame.setSize(400,400);

//Make JFrame visible. So we can see it
frame.setVisible(true);
}
}


**************************************************************************
JUST COMPILE AND EXECUTE IT
**************************************************************************
Related Posts Plugin for WordPress, Blogger...