A panel in swing is similar to Panel in AWT, is a lightweight container that is designed to group a set of components, including other panels. It is visually represented as window that does not contain a title bar, menu bar or border. It is simplest of all the containers. Its default layout manager is FlowLayout.
Panels are represented by objects created from JPanel class by calling the constructor.
public JPanel ()
After the panel has been created, other components can be added to JPanel object by calling its add (component) method inherited from the Container class. The following code fragment demonstrates creating a panel and adding two buttons to it.
JPanel p = new JPanel();
p. add (new JButton ("OK")) ;
p. add (new JButton ("Cancel") ) ;
Using panels, you can design complex GUls.
class JPanelExample extends JFrame
JPanel panel1,panel2 ;
JButton btnData = new JButton;
txtData = new JTextField(20);
panel2=new JPanel(new GridLayout(3,4));
public static void main(String args)
JPanelExample frame = new JPanelExample();
frame.setTitle("JPanel Java Example");