JPanel is a public java swing class which is used to create a general-purpose container JPanel objects that are used to group other GUI components without adding any functionality to the added components.
JPanel panel objects can add color to their background and also can be customized. JPanel inherits methods from it’s super classes namely JComponent, Container, and Component java classes. JPanel is an extension of java swing JComponent class. JPanel class implements Accessible interface.
Following is a list of constructors of JPanel Class:-
* JPanel() which creates a new JPanel panel object with a double buffer and a default flow layout * JPanel(boolean isDoubleBuffered)which creates a new JPanel panel object with FlowLayout and the buffering strategy as specified. * JPanel(LayoutManager layout) which creates a new buffered JPanel panel object with the specified layout manager * JPanel(LayoutManager layout, boolean isDoubleBuffered) which creates a new JPanel with the specified layout manager and specified buffering strategy.
Underneath is an example of java code, JpanelExample.java, which demonstrate use of JPanel in a simple GUI java program.
import javax.swing.*; import java.awt.*; & public class JPanelExample { & & public static void main(String[] args) { JFrame frame1=new JFrame("Creating a Jframe and using JPanel JComponent"); frame1.setDefaultCloseOperation(frame1.EXIT_ON_CLOSE); frame1.setSize(400,200);
Comments
Leave a comment