• 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

panels and background

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
please look at the code below
import java.awt.*;
import java.applet.*;
public class applet extends Applet
{
Panel p;
Button b;
public void init()
{
setLayout(new FlowLayout());
p=new Panel();
b=new Button("ok");
p.add(b) ;
setBackground(Color.red);
p.setBackground(Color.blue);// line 1
add(p);
setSize(200,150);
setVisible(true);
}

}
my question is that if i comment line 1 the panel takes the color red as background. How is this. is the panel by default transparent or else what is the answer
Regds.
Rahul
 
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi rahul,
this is what i read about setBackground function of component in jdk1.2.2 documentation

public void setBackground(Color c)
Sets the background color of this component.
Parameters:
c - The color to become this component's color. If this parameter is null then this component will inherit the background color of its parent. background color.

so it seems when we don't specify a color the component takes up the color of it's parent.
regards
deekasha
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi deekasha
The problem i have specifically is
I know the parent child relation ship exist between the applet and its panel.
But i am creating a new Panel with no relation with the applet.
Where from is the parent-child relationship arising
Regds
Rahul
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Parent child relationship is arising from the default Panel layout of applet (it is considered as parent)
if you add any component on it it is its child
I hope it is clear

Originally posted by rahul_mkar:
Hi deekasha
The problem i have specifically is
I know the parent child relation ship exist between the applet and its panel.
But i am creating a new Panel with no relation with the applet.
Where from is the parent-child relationship arising
Regds
Rahul


 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Could u please elaborate.
Regds.
Rahul
 
Gaurav Chikara
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are simply creating panel on a panel
doesn't it makes parent-child relationship with new panel child
of old panel?
I hope now it is clear.

Originally posted by rahul_mkar:
Hi,
Could u please elaborate.
Regds.
Rahul


 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic