• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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

 
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
 
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.
 
Looky! I'm being abducted by space aliens! Me and this tiny ad!
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic