• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic