Write down a steps to change default layout manager
Answers
Use the JPanel constructors, which accept a LayoutManager:
import java.awt.LayoutManager;
import javax.swing.JPanel;
public class MyPanel extends JPanel {
public MyPanel() {
this(true);
}
public MyPanel(boolean isDoubleBuffered) {
super(null, isDoubleBuffered);
}
public MyPanel(LayoutManager layout, boolean isDoubleBuffered) {
super(layout, isDoubleBuffered);
}
public MyPanel(LayoutManager layout) {
this(layout, true);
}
}
Solution: The only containers whose layout managers one should worry for is JPanels and content panes.
By default, content panes have Border Layout. However, one is free to change this default layout.
For any real applications, it is important to change or reset the layout manager and requires appropriate tools rather the manager by hand.
Different methods are used as per the type of changes.