Custom Layout or null Layout
“null” is a keyword of java. This tutorial is not about a any java class. And it’s also not about setting some layout. This is to remove the existing layout! And by removing the layout one can do the exact positioning of the components.
We can remove the existing layout by calling a method: setLayout(null); and then even if we try to components, that will not be displayed. To make component visible we need to invoke seBounds(x_cord, y_cord, width, height) method on all the components.
Program:
import java.applet.*; import java.awt.*; public class NullLayoutDemo extends Applet { Button b1, b2, b3; public void init() { setBackground(Color.green); setLayout(null); b1 = new Button("Button1"); b2 = new Button("Button2"); b3 = new Button("Button3"); add(b1); add(b2); add(b3); b1.setBounds(50,100, 150, 50); b2.setBounds(50,200, 150, 50); b3.setBounds(50,300, 150, 50); } } /* <applet code="NullLayoutDemo" width="500" height="500"></applet> */
Output:
Recent Comments