• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to add nullLayout to a panel? kindly see the source code inside.

 
nima lama
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am confused, the below program gets compiled but it does not show the button on the panel. i have tried adding null layout to panel with other program as but it doesn't come.
if there is a way to add null layout to a panel, please kindly tell me it is done.
import java.applet.Applet;
import java.awt.*;
//<applet code=NullPanel.class height=300 width=400></applet>
public class NullPanel extends Applet
{
Button button=new Button("Click");
Panel p;
public void init()
{
setLayout(new FlowLayout());
p=new Panel();
p.setLayout(null);

p.add(button);
button.setBounds(20,20,20,20);
add(p);
}
}
thanks
nima lama
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nima,
I think you are getting stuck because you are trying to place a null layout panel into a flowLayout panel. The way a FlowLayout works is that it queries all its components and asks for their preferred sizes. A null layout has a preferred size of 0 by 0! Therefore, the FlowLayout is not even showing your null panel because it doesn't have any preferred size!
If you want to use a null panel then just use the Applet itself and set its layout to null.

Regards,
Manfred.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic